List of usage examples for org.eclipse.jface.viewers StructuredSelection StructuredSelection
public StructuredSelection(List elements)
List
. From source file:ca.uvic.cs.tagsea.editing.TreeItemWorker.java
License:Open Source License
/** * Sets the selection on the tree. //from w w w . j ava 2s . com * Also updates the TreeViewer selection if it is not null. * The tree viewer's selection will be the data Object from each TreeItem. * @param selectedItems the tree items that are to be selected */ protected void setSelection(TreeItem[] selectedItems) { tree.setSelection(selectedItems); if (treeViewer != null) { ArrayList<Object> selectedData = new ArrayList<Object>(selectedItems.length); for (TreeItem item : selectedItems) { if ((item != null) && !item.isDisposed()) { Object data = item.getData(); if (data != null) { selectedData.add(data); } } } treeViewer.setSelection(new StructuredSelection(selectedData)); } }
From source file:ca.uvic.cs.tagsea.ui.views.RoutesComposite.java
License:Open Source License
protected void addNewRoute() { RouteCollection routeCollection = TagSEAPlugin.getDefault().getRouteCollection(); routeCollection = TagSEAPlugin.getDefault().getRouteCollection(); RouteNameValidator validator = new RouteNameValidator(routeCollection); InputDialog dlg = new InputDialog(routesTreeViewer.getTree().getShell(), "New Route Name", "Enter a name for the new route:", "", validator); if (dlg.open() == InputDialog.OK) { Route route = routeCollection.addRoute(dlg.getValue()); refreshRoutesViewer();//from ww w. jav a 2s. c om routesTreeViewer.setSelection(new StructuredSelection(route), true); routesTreeViewer.getControl().setFocus(); } }
From source file:ca.uvic.cs.tagsea.ui.views.RoutesViewStateManager.java
License:Open Source License
@SuppressWarnings("unchecked") private static void restoreStateFromMemento(RoutesComposite routesComposite, IMemento memento) { IMemento expandedRoutesMemento = memento.getChild("expandedRoutes"); IMemento selectedRoutesMemento = memento.getChild("selectedRoutes"); if (expandedRoutesMemento != null) { IMemento[] routeMementos = expandedRoutesMemento.getChildren("route"); List<Route> routes = new ArrayList<Route>(); for (IMemento m : routeMementos) { String name = m.getString("name"); if (name != null) { Route r = TagSEAPlugin.getDefault().getRouteCollection().getRoute(name); if (r != null) routes.add(r);/*from www. jav a 2 s . c o m*/ } } if (routes.size() > 0) { Route[] array = new Route[routes.size()]; array = routes.toArray(array); routesComposite.getRoutesTreeViewer().setExpandedElements(array); } } if (selectedRoutesMemento != null) { IMemento[] routeMementos = selectedRoutesMemento.getChildren("route"); IMemento[] waypointMementos = selectedRoutesMemento.getChildren("waypoint"); List selection = new ArrayList(); for (IMemento m : routeMementos) { String name = m.getString("name"); if (name != null) { Route r = TagSEAPlugin.getDefault().getRouteCollection().getRoute(name); if (r != null) selection.add(r); } } try { for (IMemento m : waypointMementos) { String id = m.getString("id"); if (id != null) { Waypoint w = TagSEAPlugin.getDefault().getTagCollection().getWaypointCollection() .getWaypoint(id); if (w != null) selection.add(w); } } } catch (RuntimeException e) { e.printStackTrace(); } if (selection.size() > 0) routesComposite.getRoutesTreeViewer().setSelection(new StructuredSelection(selection)); } }
From source file:ca.uvic.cs.tagsea.ui.views.TagsComposite.java
License:Open Source License
private void makeActions() { selectAllTagsAction = new Action("Select &All\tCtrl+A") { public void run() { TagCollection tagCollection = TagSEAPlugin.getDefault().getTagCollection(); Tag[] allTags = tagCollection.getAllTags(); tagsTreeViewer.setSelection(new StructuredSelection(allTags), false); tagsTreeViewer.getControl().setFocus(); }// w w w . j ava2 s . c o m }; selectAllTagsAction.setAccelerator(SWT.CTRL + 'A'); ImageRegistry images = TagSEAPlugin.getDefault().getImageRegistry(); ImageDescriptor collapseDesc = images.getDescriptor(KEY_COLLAPSE); ImageDescriptor collapseDescDis = images.getDescriptor(KEY_COLLAPSE_DIS); ImageDescriptor expandDesc = images.getDescriptor(KEY_EXPAND); ImageDescriptor expandDescDis = images.getDescriptor(KEY_EXPAND_DIS); collapseTagsAction = new Action("Collapse All", collapseDesc) { public void run() { tagsTreeViewer.collapseAll(); } }; collapseTagsAction.setDisabledImageDescriptor(collapseDescDis); expandTagsAction = new Action("Expand All", expandDesc) { public void run() { tagsTreeViewer.expandAll(); } }; expandTagsAction.setDisabledImageDescriptor(expandDescDis); final ISharedImages workbenchImages = PlatformUI.getWorkbench().getSharedImages(); ImageDescriptor deleteDescriptor = workbenchImages.getImageDescriptor(ISharedImages.IMG_TOOL_DELETE); ImageDescriptor deleteDescriptorDis = workbenchImages .getImageDescriptor(ISharedImages.IMG_TOOL_DELETE_DISABLED); deleteAction = new Action("Delete", deleteDescriptor) { public void run() { TreeItem[] selection = tagsTreeViewer.getTree().getSelection(); if (selection.length == 1) { tagsWorker.deleteTreeItem(selection[0], true); } } }; deleteAction.setToolTipText("Delete this tag"); deleteAction.setDisabledImageDescriptor(deleteDescriptorDis); renameAction = new Action("Rename") { public void run() { TreeItem[] selection = tagsTreeViewer.getTree().getSelection(); if (selection.length == 1) { tagsWorker.renameTreeItem(selection[0]); } } }; renameAction.setToolTipText("Rename the selected tag."); generalizeAction = new Action("Generalize") { public void run() { // @tag Editing(Generalize): need to implement } }; generalizeAction.setEnabled(false); }
From source file:ca.uvic.cs.tagsea.ui.views.TagsComposite.java
License:Open Source License
/** * Refreshes the tags tree viewer.// www. jav a2 s .co m */ public void refreshTagsViewer(Object element) { // get selected and expanded id's so we can maintain the view state String[] selectedIdList = getSelectedList(); String[] expandedIdList = getExpandedList(); if (element == null) { tagsTreeViewer.refresh(); } else { tagsTreeViewer.refresh(element); } // reselect the tags that were selected prior to the refresh Tag[] tags = TagSEAPlugin.getDefault().getTagCollection().getTags(expandedIdList); tagsTreeViewer.setExpandedElements(tags); tagsTreeViewer.setSelection( new StructuredSelection(TagSEAPlugin.getDefault().getTagCollection().getTags(selectedIdList))); //tagsTreeViewer.getControl().setFocus(); }
From source file:ca.uvic.cs.tagsea.ui.views.TagsViewStateManager.java
License:Open Source License
private static void restoreStateFromMemento(TagsComposite tagsComposite, IMemento memento) { IMemento selectedTagsMemento = memento.getChild("selectedTags"); IMemento expandedTagsMemento = memento.getChild("expandedTags"); if (expandedTagsMemento != null) { IMemento[] tagMementos = expandedTagsMemento.getChildren("tag"); List<String> tagIds = new ArrayList<String>(); for (IMemento tagMemento : tagMementos) { String tagId = tagMemento.getString("tag-id"); if (tagId != null) tagIds.add(tagId);// www .ja v a 2 s. c o m } if (tagIds.size() > 0) { String[] array = new String[tagIds.size()]; array = tagIds.toArray(array); Tag[] expandedTags = TagSEAPlugin.getDefault().getTagCollection().getTags(array); if (expandedTags.length > 0) tagsComposite.getTagsTreeViewer().setExpandedElements(expandedTags); } } if (selectedTagsMemento != null) { IMemento[] tagMementos = selectedTagsMemento.getChildren("tag"); List<String> tagIds = new ArrayList<String>(); for (IMemento tagMemento : tagMementos) { String tagId = tagMemento.getString("tag-id"); if (tagId != null) tagIds.add(tagId); } if (tagIds.size() > 0) { String[] array = new String[tagIds.size()]; array = tagIds.toArray(array); Tag[] selectedTags = TagSEAPlugin.getDefault().getTagCollection().getTags(array); if (selectedTags.length > 0) tagsComposite.getTagsTreeViewer().setSelection(new StructuredSelection(selectedTags)); } } }
From source file:ca.uvic.cs.tagsea.ui.views.WaypointsComposite.java
License:Open Source License
private void makeActions() { selectAllAction = new Action("Select All") { public void run() { Object[] elements = waypointProvider.getElements(null); waypointsTableViewer.setSelection(new StructuredSelection(elements)); waypointsTableViewer.getControl().setFocus(); }// ww w.j a va 2s .co m }; }
From source file:ca.uwaterloo.gp.fmp.presentation.FmpEditor.java
License:Open Source License
/** * This sets the selection into whichever viewer is active. * <!-- begin-user-doc -->//from w ww .j a v a 2 s .com * <!-- end-user-doc --> * @generated */ public void setSelectionToViewer(Collection collection) { final Collection theSelection = collection; // Make sure it's okay. // if (theSelection != null && !theSelection.isEmpty()) { // I don't know if this should be run this deferred // because we might have to give the editor a chance to process the viewer update events // and hence to update the views first. // // Runnable runnable = new Runnable() { public void run() { // Try to select the items in the current content viewer of the editor. // if (currentViewer != null) { currentViewer.setSelection(new StructuredSelection(theSelection.toArray()), true); } } }; runnable.run(); } }
From source file:ca.uwaterloo.gp.fmp.presentation.FmpEditor.java
License:Open Source License
/** * This accesses a cached version of the content outliner. * <!-- begin-user-doc -->// w ww. j a va2s .c o m * <!-- end-user-doc --> * @generated */ public IContentOutlinePage getContentOutlinePage() { if (contentOutlinePage == null) { // The content outline is just a tree. // class MyContentOutlinePage extends ContentOutlinePage { public void createControl(Composite parent) { super.createControl(parent); contentOutlineViewer = getTreeViewer(); contentOutlineViewer.addSelectionChangedListener(this); // Set up the tree viewer. // contentOutlineViewer.setContentProvider(new AdapterFactoryContentProvider(adapterFactory) { // make sure only root features and their configurations are shown public Object[] getChildren(Object object) { if (object instanceof Feature) { Feature node = (Feature) object; if (RoleQuery.INSTANCE.getNodeType(node) == RoleQuery.ROOT_FEATURE) return ((Feature) object).getConfigurations().toArray(); else if (RoleQuery.INSTANCE.getNodeType(node) == RoleQuery.FEATURE_MODEL) return ((Feature) object).getChildren().toArray(); } return Collections.EMPTY_LIST.toArray(); } public boolean hasChildren(Object object) { if (object instanceof Feature) { Feature node = (Feature) object; if (RoleQuery.INSTANCE.getNodeType(node) == RoleQuery.ROOT_FEATURE) return !((Feature) object).getConfigurations().isEmpty(); else if (RoleQuery.INSTANCE.getNodeType(node) == RoleQuery.FEATURE_MODEL) return !((Feature) object).getChildren().isEmpty(); } return false; } }); contentOutlineViewer.setLabelProvider(new AdapterFactoryLabelProvider(adapterFactory)); contentOutlineViewer.setInput(getModel()); // Make sure our popups work. // createContextMenuFor(contentOutlineViewer); if (!editingDomain.getResourceSet().getResources().isEmpty()) { // Select the root object in the view. // ArrayList selection = new ArrayList(); selection.add(editingDomain.getResourceSet().getResources().get(0)); contentOutlineViewer.setSelection(new StructuredSelection(selection), true); } } public void makeContributions(IMenuManager menuManager, IToolBarManager toolBarManager, IStatusLineManager statusLineManager) { super.makeContributions(menuManager, toolBarManager, statusLineManager); contentOutlineStatusLineManager = statusLineManager; } public void setActionBars(IActionBars actionBars) { super.setActionBars(actionBars); getActionBarContributor().shareGlobalActions(this, actionBars); } } contentOutlinePage = new MyContentOutlinePage(); // Listen to selection so that we can handle it is a special way. // contentOutlinePage.addSelectionChangedListener(new ISelectionChangedListener() { // This ensures that we handle selections correctly. // public void selectionChanged(SelectionChangedEvent event) { handleContentOutlineSelection(event.getSelection()); } }); } return contentOutlinePage; }
From source file:ca.uwaterloo.gp.fmp.presentation.FmpEditor.java
License:Open Source License
/** * This deals with how we want selection in the outliner to affect the other views. * <!-- begin-user-doc -->//www .ja va 2 s. c om * <!-- end-user-doc --> * Michal: use modelingViewer * @generated NOT */ public void handleContentOutlineSelection(ISelection selection) { if (currentViewerPane != null && !selection.isEmpty() && selection instanceof IStructuredSelection) { Iterator selectedElements = ((IStructuredSelection) selection).iterator(); if (selectedElements.hasNext()) { // Get the first selected element. // Object selectedElement = selectedElements.next(); // If it's the modeling viewer, then we want it to select the same selection as this selection. // if (currentViewerPane.getViewer() == modelingViewer) { ArrayList selectionList = new ArrayList(); selectionList.add(selectedElement); while (selectedElements.hasNext()) { selectionList.add(selectedElements.next()); } // Set the selection to the widget. // modelingViewer.setSelection(new StructuredSelection(selectionList)); } else if (currentViewerPane.getViewer() == configurationViewer) { if (selectedElement instanceof Feature && ((Feature) selectedElement) .eContainingFeature() == FmpPackage.eINSTANCE.getFeature_Configurations()) { configurationViewer.setInput(selectedElement); currentViewerPane.setTitle(selectedElement); } } } } }