List of usage examples for org.eclipse.jface.viewers IStructuredSelection iterator
@Override
public Iterator iterator();
From source file:com.nokia.tools.s60.editor.Series60ContentOutlinePage.java
License:Open Source License
public void selectionChanged(SelectionChangedEvent event) { if (getEditorPart() == null) { return;//w ww . ja v a2s .co m } if (!isViewerDispatching && event.getSource() == categoryViewer) { isCategoryDispatching = true; try { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); List selectedEditParts = selection.toList(); List<Object> treeParts = new ArrayList<Object>(selectedEditParts.size()); List<Object> graphicalParts = new ArrayList<Object>(selectedEditParts.size()); for (Object obj : selectedEditParts) { if (obj instanceof TreeEditPart) { treeParts.add(obj); } else if (obj instanceof GraphicalEditPart) { graphicalParts.add(obj); } } if (!treeParts.isEmpty()) { getViewer().setSelection(new StructuredSelection(treeParts)); } if (!graphicalParts.isEmpty()) { GraphicalViewer viewer = (GraphicalViewer) getEditorPart().getAdapter(GraphicalViewer.class); if (viewer != null) { viewer.setSelection(new StructuredSelection(graphicalParts)); } } /* synchronize selection in editor with this */ List newSelection = new ArrayList(); for (Iterator iter = selection.iterator(); iter.hasNext();) { TreeNode node = (TreeNode) iter.next(); IScreenElement screenElem = null; if (node.getContent() instanceof IScreenElement) { screenElem = (IScreenElement) node.getContent(); } else if (node.getContent() instanceof IContentData) { TreeNode last = node; while (last.getChildren().size() == 1) { last = last.getChildren().iterator().next(); } if (last.getContent() instanceof IScreenElement) { screenElem = (IScreenElement) last.getContent(); } } if (screenElem != null && getViewer() != null) { EditPart part = (EditPart) getViewer().getEditPartRegistry().get(screenElem.getWidget()); if (part != null) { newSelection.add(part); } } } if (getViewer() != null) { if (!newSelection.isEmpty()) { getViewer().setSelection(new StructuredSelection(newSelection)); } else { getViewer().deselectAll(); } } } finally { isCategoryDispatching = false; } } else if (!isCategoryDispatching && event.getSource() == getEditorPart().getAdapter(GraphicalViewer.class)) { isViewerDispatching = true; try { List selectedParts = ((IStructuredSelection) event.getSelection()).toList(); List newSelection = new ArrayList(); for (Object part : selectedParts) { EObject model = (EObject) ((EditPart) part).getModel(); IScreenElement data = (IScreenElement) JEMUtil.getScreenElement(model); if (data != null) { // data can be null when the freeform is selected if (data.getWidget() != model) { IScreenElement[] elems = (IScreenElement[]) data.getData() .getAdapter(IScreenElement[].class); if (elems != null) { for (int i = 0; i < elems.length; i++) { IScreenElement elem = elems[i]; if (elem.getWidget() == model) { data = elem; break; } } } } TreeNode root = (TreeNode) categoryViewer.getInput(); if (root != null) { TreeNode node = findNode(root, data); if (node != null) { newSelection.add(node); categoryViewer.expandToLevel(node, 0); } } } } categoryViewer.setSelection(new StructuredSelection(newSelection)); } finally { isViewerDispatching = false; } } }
From source file:com.nokia.tools.s60.views.IconViewPage.java
License:Open Source License
protected void repopulateContents(final IStructuredSelection ssel) { // keeps the last selection, so we can refresh the entire category when // some children have been added or removed lastSelection = ssel;//from w w w . j a v a 2 s . c o m for (EditObject resource : resources) { ComponentAdapter adapter = (ComponentAdapter) EcoreUtil.getExistingAdapter(resource, ComponentAdapter.class); resource.eAdapters().remove(adapter); } resources.clear(); if (container == null || container.isDisposed()) { return; } clearArea(); Set<IContentData> selection = new HashSet<IContentData>(); if (ssel != null) { for (Iterator iter = ssel.iterator(); iter.hasNext();) { Object obj = iter.next(); if (obj instanceof IContentData) { selection.add((IContentData) obj); } } } List<Object> newSelection = new ArrayList<Object>(); // populate all leafs of category try { List<IContentData> childrenList = getItems(); for (final IContentData child : childrenList) { final ImageLabel control = new ImageLabel(container, SWT.NONE); control.setUnselectedBackground(container.getBackground()); control.setSelectedBackground(container.getBackground()); control.setData(child); control.addKeyListener(IconViewPage.this); EditObject resource = (EditObject) child.getAdapter(EditObject.class); resource.eAdapters().add(new ComponentAdapter(control)); resources.add(resource); IContentData parent = child.getParent(); if (parent != null) { EditObject parentResource = (EditObject) parent.getAdapter(EditObject.class); if (parentResource != null && EcoreUtil.getExistingAdapter(parentResource, ComponentAdapter.class) == null) { parentResource.eAdapters().add(new ComponentAdapter(null)); resources.add(parentResource); } } if (toggleTextAction != null) { control.setLines(toggleTextAction.isChecked() ? IS60IDEConstants.IMAGE_LABEL_TEXT_LINES : 0); } ISkinnableEntityAdapter ska = (ISkinnableEntityAdapter) child .getAdapter(ISkinnableEntityAdapter.class); control.setModified(ska != null && ska.isSkinned()); ISkinnableContentDataAdapter scda = (ISkinnableContentDataAdapter) child .getAdapter(ISkinnableContentDataAdapter.class); if (scda != null) { control.setModified(scda.isElementSkinned()); control.redraw(); } if (selection.contains(child)) { newSelection.add(child); control.setSelected(true); } mouseRightClicked = false; // look if we can get right image, if not, // get default control.setImageDescriptor(getImageDescriptor(child)); control.setText(child.getName()); IconTooltip tooltip = new IconTooltip(findScreenData(child), this, getCommandStack()); control.setData(tooltip.getClass().getName(), tooltip); if (tooltip.getContributionsCount(false) == 0) { // no tooltip contribution // so use standard tooltip control.setToolTipText(child.getName()); } else { tooltip.setControl(control); } control.addSelectionListener(new ImageLabel.SelectedListener() { public void selected(EventObject e) { if (!selectedItems.contains(((ImageLabel) e.getSource()).getData())) { ((ImageLabel) e.getSource()).setSelected(false); } } }); control.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { mouseButtonDown(e); if (e.button == 3) { mouseRightClicked = true; } final IconTooltip tooltip = (IconTooltip) control.getData(IconTooltip.class.getName()); if (tooltip != null) { if (e.button == 3) { tooltip.hide(); } tooltip.disable(); Display.getDefault().asyncExec(new Runnable() { public void run() { if (tooltip != null) { tooltip.enable(); } } }); } } @Override public void mouseUp(MouseEvent e) { if (mouseButtonUp(e)) { return; } if (e.button == 1) { if (ctrl_active && shift_active) { updateSelection(child, SelectionMode.CTRL_SHIFT); } else if (shift_active) { updateSelection(child, SelectionMode.SHIFT); } else if (ctrl_active) { updateSelection(child, SelectionMode.CTRL); } else { selectionStart = child; selfSetSelection(new StructuredSelection(child)); } } else if (e.button == 3) { if (selectedItems == null || !selectedItems.contains(child)) { selectionStart = child; updateSelection(child, SelectionMode.NORMAL); } } mouseRightClicked = false; } @Override public void mouseDoubleClick(MouseEvent e) { if (e.count == 2) { handleDoubleClick(child); } } }); MouseMoveListener mouseMoveListener = new MouseMoveListener() { public void mouseMove(MouseEvent e) { mouseMoved(e); } }; control.addMouseMoveListener(mouseMoveListener); MenuManager menuMgr = new MenuManager("#PopupMenu"); menuMgr.setRemoveAllWhenShown(true); menuMgr.addMenuListener(new IMenuListener() { public void menuAboutToShow(IMenuManager manager) { IIconMenuProvider imp = (IIconMenuProvider) sourceEditor .getAdapter(IIconMenuProvider.class); if (imp != null) { imp.fillIconContextMenu(manager, IconViewPage.this.parent, "components", getCommandStack(), getSite().getActionBars()); } } }); Menu menu = menuMgr.createContextMenu(control); control.setMenu(menu); // drag and drop support addDragDropSupport(control, child); } if (container != null && !container.isDisposed()) { container.layout(); scrollableComposite.setMinSize(container.computeSize(SWT.DEFAULT, SWT.DEFAULT)); container.redraw(); } } catch (Exception e) { e.printStackTrace(); } // add flags about synchronize with editor if (ssel.size() > 0 && ssel.toArray()[ssel.size() - 1] == Boolean.FALSE) newSelection.add(Boolean.FALSE); setSelection(new StructuredSelection(newSelection)); }
From source file:com.nokia.tools.s60.views.IconViewPage.java
License:Open Source License
public void setSelection(final ISelection selection) { if (container == null || container.isDisposed()) { return;/*w ww . j av a 2 s.co m*/ } if (suppressSelectEvent) { return; } if (currentCategory == null) { refreshIconViewActionsState(); return; } if (selection instanceof IStructuredSelection) { final IStructuredSelection sselection = (IStructuredSelection) selection; /** * Should not be used as then when selection changes in editor the * same element can not be reselected but have to visit other * element first */ if (selectedItems != null && selectedItems.size() == 1 && !selection.isEmpty() && selectedItems.get(0) == ((IStructuredSelection) selection).getFirstElement()) { itemReSelected = true; } else { itemReSelected = false; } List<IContentData> newSelection = new ArrayList<IContentData>(); for (Iterator iter = sselection.iterator(); iter.hasNext();) { Object obj = iter.next(); if (obj instanceof IContentData) { IContentData modelData = currentCategory.findById(((IContentData) obj).getId()); if (modelData == null) continue; // set screen context to theme data, will be needed to // creating // bean-widget for elements that don't have screen // element modelData.getAdapter(EditObject.class); newSelection.add(modelData); } else { // select from screen widgets IScreenElement se = JEMUtil.getScreenElement(obj); if (se != null) { // handles colors ICategoryAdapter ca = (ICategoryAdapter) se.getData().getAdapter(ICategoryAdapter.class); IContentData[] peers = ca.getCategorizedPeers(); for (IContentData peer : peers) { newSelection.add(peer); } } } } selectedItems = newSelection; if (!selectedItems.contains(selectionStart)) { selectionStart = null; } // notifies listeners before revealing in the editor because the // statue line may otherwise be changed by other views suppressSelectEvent = true; try { SelectionChangedEvent event = new SelectionChangedEvent(this, getSelection()); for (ISelectionChangedListener l : listeners) { try { l.selectionChanged(event); } catch (Exception e) { e.printStackTrace(); } } } finally { suppressSelectEvent = false; } Control[] controls = container.getChildren(); IContentData last = newSelection.isEmpty() ? null : newSelection.get(newSelection.size() - 1); for (Control ctrl : controls) { ImageLabel label = (ImageLabel) ctrl; if (ctrl.getData() == last) { scrollToVisible(ctrl); } if (newSelection.contains(ctrl.getData())) { label.setSelected(true); } else { label.setSelected(false); } } if (synchronize) { if (!(sselection.size() > 0 && sselection.toArray()[sselection.size() - 1] == Boolean.FALSE)) { suppressSelectEvent = true; try { showSelectionInEditor((IStructuredSelection) selection); } finally { suppressSelectEvent = false; } } } } suppressSelectEvent = true; try { ((IconView) parent).fireSelectionChangeEvent(); } finally { suppressSelectEvent = false; } refreshIconViewActionsState(); }
From source file:com.nokia.tools.screen.ui.propertysheet.tabbed.MultipleSelectionWidgetSection.java
License:Open Source License
public final void setInput(IWorkbenchPart part, ISelection selection) { super.setInput(part, selection); removeRefreshAdapters();/* www .j a va 2s . c om*/ elements = new ArrayList<IScreenElement>(); targets = new ArrayList<EObject>(); widgets = new ArrayList<EObject>(); contents = new ArrayList<IContentData>(); IStructuredSelection ssel = (IStructuredSelection) selection; for (Iterator iter = ssel.iterator(); iter.hasNext();) { Object obj = iter.next(); IScreenElement adapter = JEMUtil.getScreenElement(obj); if (adapter != null) { IScreenElement element = adapter; if (adapter.getTargetAdapter() != null) { adapter = adapter.getTargetAdapter(); } EObject target = doSetInput(part, adapter); if (target != null) { if (!(elements.contains(element) && targets.contains(target))) { elements.add(element); targets.add(target); widgets.add(adapter.getWidget()); contents.add(element.getData()); } } else { IContentData data = JEMUtil.getContentData(obj); if (data != null) { contents.add(data); } } } else { IContentData data = JEMUtil.getContentData(obj); if (data != null) { contents.add(data); } } } for (EObject target : targets) { addRefreshAdapter(target); } for (IContentData data : contents) { addRefreshAdapter(data); } clearErrorMessage(); }
From source file:com.nokia.tools.screen.ui.views.ResourcePage.java
License:Open Source License
/** * shows and selects element (group), that contains item in selection * /*from ww w .j av a2 s . c om*/ */ public void showSelection(IStructuredSelection sel) { if (viewer == null) return; Object data = sel.isEmpty() ? null : sel.getFirstElement(); // IContentData modelItem = findModelItem(data, themeContent); IContentData modelItem = findModelItem(data); IResourceViewerSelectionHelper helper = viewer.getResourceSelectionHelper(modelItem); if (modelItem != null) { // find Task and ComponentGroup, that contains selection IContentData task = helper.findTaskContaining(modelItem); if (task == null) return; final IContentData compGroup = helper.findGroupContaining(modelItem, task); final IContentData minorGroup = helper.findMinorGroup(modelItem, task, compGroup); // selects appropriate elements if (compGroup != null && minorGroup != null) { suppressViewerEvents = true; try { final Map map = viewer.getVisualPartMap(); Iterator it = map.values().iterator(); while (it.hasNext()) { EditPart element = (EditPart) it.next(); if (element.getModel() instanceof CombinedTemplateCreationEntry) { CombinedTemplateCreationEntry entry = (CombinedTemplateCreationEntry) element .getModel(); if (entry.getTemplate() == compGroup || entry.getTemplate() == minorGroup) { // set viewer selection is the same no // action if (viewer.getSelectedEditParts().size() == 0 || viewer.getSelectedEditParts().get(0) != element) { viewer.reveal(element); viewer.select(element); viewer.setActiveTool(entry); } if (viewer // enter only if the section supports // position viewer .getResourceSelectionHelper(compGroup).supportsPositionViewer()) { // update also selection in position viewer if (minorGroup != null) { it = positionViewer.getVisualPartMap().values().iterator(); while (it.hasNext()) { element = (EditPart) it.next(); if (element.getModel() instanceof CombinedTemplateCreationEntry) { entry = (CombinedTemplateCreationEntry) element.getModel(); if (entry.getTemplate() == minorGroup) { if (positionViewer.getSelectedEditParts().size() == 0 || positionViewer.getSelectedEditParts() .get(0) != element) { IResourceSection section = viewer .getResourceSection(modelItem); if (section instanceof IResourceViewRectProvider) { positionViewer.rectProvider = (IResourceViewRectProvider) section; } positionViewer.reveal(element); _shouldRefreshIconView = false; positionViewer.select(element); } List<Object> iconViewSel = new ArrayList<Object>(); for (Iterator iter = sel.iterator(); iter.hasNext();) { IContentData mItem = findModelItem(iter.next()); if (mItem != null) { iconViewSel.add(mItem); } } /* * add parameter * 'Boolean.FALSE' to * selection so that icon * view will be notified tot * to try synchronize with * editor and stuck in * event-loop */ _shouldRefreshIconView = true; iconViewSel.add(Boolean.FALSE); refreshIconView(new StructuredSelection(iconViewSel), false); return; } } } } } else { // the section does not support // position viewer, clear it updatePositionViewer(null); refreshIconView(new StructuredSelection(new Object[] { Boolean.FALSE }), false); } return; } } } } finally { suppressViewerEvents = false; } } } else { refreshIconView(new StructuredSelection(new Object[] { Boolean.FALSE }), false); return; } }
From source file:com.nokia.tools.theme.s60.ui.preferences.ThirdPartyIconsPrefPage.java
License:Open Source License
/** * @param generalComposite/*from w ww . j a v a2s . c o m*/ */ private void createTableForToolSpecificTPI(Composite generalComposite) { GridLayout layout; GridData gd; Composite thirdPartyComposite = new Composite(generalComposite, SWT.NONE); gd = new GridData(GridData.FILL_BOTH); thirdPartyComposite.setLayoutData(gd); layout = new GridLayout(); layout.numColumns = 2; layout.marginHeight = 0; layout.marginWidth = 0; layout.verticalSpacing = 7; thirdPartyComposite.setLayout(layout); Composite tableComposite = new Composite(thirdPartyComposite, SWT.NONE); FillLayout layout2 = new FillLayout(); tableComposite.setLayout(layout2); layout2.marginHeight = 0; layout2.marginWidth = 0; gd = new GridData(GridData.FILL_BOTH); gd.verticalSpan = 5; tableComposite.setLayoutData(gd); toolSpecificTPIViewer = new TableViewer(tableComposite, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER); initializeThirdPartyIconTableViewer(toolSpecificTPIViewer); toolSpecificTPIViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { // refresh buttons state ISelection s = event.getSelection(); toolSpecificRemove.setEnabled(!s.isEmpty()); if (!s.isEmpty() && s instanceof IStructuredSelection) { IStructuredSelection selection = (IStructuredSelection) s; removeAllBackgroundHighlights(); // Clearing previous highlighting for the conflicts which were shown earlier. Iterator iterator = selection.iterator(); while (iterator.hasNext()) { Object selectedItem = iterator.next(); if (selectedItem instanceof ThirdPartyIcon) { highlightConflictDataForTPI((ThirdPartyIcon) selectedItem); } } } } }); toolSpecificTPIViewer.getTable().addKeyListener(new org.eclipse.swt.events.KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.keyCode == SWT.DEL && toolSpecificThirdPartyIconsModel != null && toolSpecificTPIViewer.getTable().getSelectionIndex() >= 0) { toolSpecificThirdPartyIconsModel.remove(toolSpecificTPIViewer.getTable().getSelectionIndex()); refreshViewers(); } } }); toolSpecificAdd = new Button(thirdPartyComposite, SWT.NONE); toolSpecificAdd.setText(Messages.Icons3rd_add); calculateButtonSize(toolSpecificAdd); toolSpecificRemove = new Button(thirdPartyComposite, SWT.NONE); toolSpecificRemove.setText(Messages.Icons3rd_delete); calculateButtonSize(toolSpecificRemove); toolSpecificRemoveAllConflicts = new Button(thirdPartyComposite, SWT.NONE); toolSpecificRemoveAllConflicts.setText(Messages.Icons3rd_btnRemoveConflicts); calculateButtonSize(toolSpecificRemoveAllConflicts); toolSpecificRemoveAll = new Button(thirdPartyComposite, SWT.NONE); toolSpecificRemoveAll.setText(Messages.Icons3rd_btnRemoveAll); calculateButtonSize(toolSpecificRemoveAll); toolSpecificAdd.addSelectionListener(this); toolSpecificRemove.addSelectionListener(this); toolSpecificRemoveAllConflicts.addSelectionListener(this); toolSpecificRemoveAll.addSelectionListener(this); toolSpecificRemove.setEnabled(false); }
From source file:com.nokia.tools.theme.s60.ui.preferences.ThirdPartyIconsPrefPage.java
License:Open Source License
/** * @param generalComposite// w w w . j a v a2 s . c o m */ private void createTableForThemeSpecificTPI(Composite generalComposite) { GridLayout layout; GridData gd; Label themeSpecificLabel = new Label(generalComposite, SWT.HORIZONTAL | SWT.VERTICAL); themeSpecificLabel.setText("Theme Specific Icons:"); Composite thirdPartyComposite = new Composite(generalComposite, SWT.NONE); gd = new GridData(GridData.FILL_BOTH); thirdPartyComposite.setLayoutData(gd); layout = new GridLayout(); layout.numColumns = 2; layout.marginHeight = 0; layout.marginWidth = 0; layout.verticalSpacing = 7; thirdPartyComposite.setLayout(layout); Composite tableComposite = new Composite(thirdPartyComposite, SWT.NONE); FillLayout layout2 = new FillLayout(); tableComposite.setLayout(layout2); layout2.marginHeight = 0; layout2.marginWidth = 0; gd = new GridData(GridData.FILL_BOTH); gd.verticalSpan = 5; tableComposite.setLayoutData(gd); themeSpecificTPIViewer = new TableViewer(tableComposite, SWT.MULTI | SWT.FULL_SELECTION | SWT.BORDER); initializeThirdPartyIconTableViewer(themeSpecificTPIViewer); themeSpecificTPIViewer.addSelectionChangedListener(new ISelectionChangedListener() { public void selectionChanged(SelectionChangedEvent event) { // refresh buttons state ISelection s = event.getSelection(); themeSpecificRemove.setEnabled(!s.isEmpty()); if (!s.isEmpty() && s instanceof IStructuredSelection) { IStructuredSelection selection = (IStructuredSelection) s; removeAllBackgroundHighlights(); // Clearing previous highlighting for the conflicts which were shown earlier. Iterator iterator = selection.iterator(); while (iterator.hasNext()) { Object selectedItem = iterator.next(); if (selectedItem instanceof ThirdPartyIcon) { highlightConflictDataForTPI((ThirdPartyIcon) selectedItem); } } } } }); themeSpecificTPIViewer.getTable().addKeyListener(new org.eclipse.swt.events.KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.keyCode == SWT.DEL && themeSpecificThirdPartyIconsModel != null && themeSpecificTPIViewer.getTable().getSelectionIndex() >= 0) { themeSpecificThirdPartyIconsModel.remove(themeSpecificTPIViewer.getTable().getSelectionIndex()); refreshViewers(); } } }); themeSpecificAdd = new Button(thirdPartyComposite, SWT.NONE); themeSpecificAdd.setText(Messages.Icons3rd_add); calculateButtonSize(themeSpecificAdd); themeSpecificRemove = new Button(thirdPartyComposite, SWT.NONE); themeSpecificRemove.setText(Messages.Icons3rd_delete); calculateButtonSize(themeSpecificRemove); themeSpecificRemoveAllConflicts = new Button(thirdPartyComposite, SWT.NONE); themeSpecificRemoveAllConflicts.setText(Messages.Icons3rd_btnRemoveConflicts); calculateButtonSize(themeSpecificRemoveAllConflicts); themeSpecificRemoveAll = new Button(thirdPartyComposite, SWT.NONE); themeSpecificRemoveAll.setText(Messages.Icons3rd_btnRemoveAll); calculateButtonSize(themeSpecificRemoveAll); themeSpecificAdd.addSelectionListener(this); themeSpecificRemove.addSelectionListener(this); themeSpecificRemoveAll.addSelectionListener(this); themeSpecificRemoveAllConflicts.addSelectionListener(this); themeSpecificRemove.setEnabled(false); }
From source file:com.opcoach.e34.tools.views.MigrationStatsView.java
License:Open Source License
@Override public void selectionChanged(IWorkbenchPart part, ISelection selection) { if (selection.isEmpty()) return;// w ww. ja v a2 s. c om // Try to find selected plugins in selection if (selection instanceof IStructuredSelection) { IStructuredSelection ss = (IStructuredSelection) selection; currentSelectedPlugins = new HashSet<IPluginModelBase>(); for (@SuppressWarnings("unchecked") Iterator<IPluginModelBase> it = ss.iterator(); it.hasNext();) { Object selected = it.next(); IProject proj = (IProject) Platform.getAdapterManager().getAdapter(selected, IProject.class); if (proj != null) { IPluginModelBase m = PDECore.getDefault().getModelManager().findModel(proj); if (m != null) { currentSelectedPlugins.add(m); } else { // Try to see if it is a feature. IFeatureModel fm = PDECore.getDefault().getFeatureModelManager().getFeatureModel(proj); if (fm != null) { for (IFeaturePlugin fp : fm.getFeature().getPlugins()) { IPluginModelBase pm = PDECore.getDefault().getModelManager().findModel(fp.getId()); if (pm != null) currentSelectedPlugins.add(pm); } } } } } mergeTableViewerColumns(currentSelectedPlugins); if (tv != null) { // Must refresh without filter and then refilter... tv.setFilters(new ViewerFilter[] {}); tv.setFilters(new ViewerFilter[] { filter }); } updateDashboard(); } }
From source file:com.puppetlabs.geppetto.pp.dsl.ui.editor.findrefs.PPReferenceSearchViewPage.java
License:Open Source License
protected void handleOpen(OpenEvent openEvent) { ISelection selection = openEvent.getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection = (IStructuredSelection) selection; for (Iterator<?> i = structuredSelection.iterator(); i.hasNext();) { Object selectedObject = i.next(); if (selectedObject instanceof ReferenceSearchViewTreeNode) { ReferenceSearchViewTreeNode treeNode = (ReferenceSearchViewTreeNode) selectedObject; Object description = treeNode.getDescription(); // open resource or a reference (standard EReference, or the PP way). if (description instanceof IReferenceDescription) { IReferenceDescription referenceDescription = (IReferenceDescription) description; // Asssume that the PP way is always to pass null as EReference if (referenceDescription.getEReference() != null) { uriEditorOpener.open(referenceDescription.getSourceEObjectUri(), referenceDescription.getEReference(), referenceDescription.getIndexInList(), true);// www . j a va 2 s. c o m } else { // Do it the PP way. uriEditorOpener.open(referenceDescription.getSourceEObjectUri(), true); } } else if (description instanceof IResourceDescription) { uriEditorOpener.open(((IResourceDescription) description).getURI(), true); } } } } }
From source file:com.quantcomponents.ui.marketdata.MarketDataManagersView.java
License:Open Source License
@Override public void createPartControl(Composite parent) { this.parent = parent; dataManagerTree = new TreeViewer(parent); dataManagerTree.setContentProvider(new BaseWorkbenchContentProvider() { @SuppressWarnings("unchecked") @Override//from w w w . j a v a2 s . c o m public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { super.inputChanged(viewer, oldInput, newInput); if (oldInput != null) { ((IMonitorableContainer<MarketDataManagerPresentationWrapper>) oldInput) .removeListener(marketDataManagerContainerListener); } if (newInput != null) { IMonitorableContainer<MarketDataManagerPresentationWrapper> container = (IMonitorableContainer<MarketDataManagerPresentationWrapper>) newInput; container.addListener(marketDataManagerContainerListener); for (MarketDataManagerPresentationWrapper manager : container.getElements()) { marketDataManagerContainerListener.onElementAdded(manager); } } } }); ILabelDecorator decorator = PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator(); dataManagerTree.setLabelProvider(new DecoratingLabelProvider(new WorkbenchLabelProvider(), decorator)); Platform.getAdapterManager().registerAdapters(adapterFactory, IMarketDataManagerContainer.class); Platform.getAdapterManager().registerAdapters(adapterFactory, MarketDataManagerPresentationWrapper.class); Platform.getAdapterManager().registerAdapters(adapterFactory, StockDatabasePresentationWrapper.class); dataManagerTree.setInput(marketDataManagerContainer); dataManagerTree.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(SelectionChangedEvent event) { multipleStockDatabaseSelection.clear(); ISelection selection = event.getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection = (IStructuredSelection) selection; Object o = structuredSelection.getFirstElement(); if (o instanceof MarketDataManagerPresentationWrapper) { selectedMarketDataManager = (MarketDataManagerPresentationWrapper) o; openViewAction.setEnabled(false); addStockDatabaseAction.setEnabled(true); removeStockDatabaseAction.setEnabled(false); if (selectedMarketDataManager instanceof RealTimeMarketDataManagerPresentationWrapper) { startAutoUpdateAction.setEnabled(false); stopAutoUpdateAction.setEnabled(false); } } else if (o instanceof StockDatabasePresentationWrapper) { openViewAction.setEnabled(true); addStockDatabaseAction.setEnabled(true); removeStockDatabaseAction.setEnabled(true); if (selectedMarketDataManager instanceof RealTimeMarketDataManagerPresentationWrapper) { startAutoUpdateAction.setEnabled(true); stopAutoUpdateAction.setEnabled(true); } if (structuredSelection.size() > 0) { Iterator<?> iterator = structuredSelection.iterator(); while (iterator.hasNext()) { Object sel = iterator.next(); if (sel instanceof StockDatabasePresentationWrapper) { StockDatabasePresentationWrapper stockDatabaseWrapper = (StockDatabasePresentationWrapper) sel; selectedMarketDataManager = stockDatabaseWrapper.getParent(); multipleStockDatabaseSelection.add(stockDatabaseWrapper); } } } } else { openViewAction.setEnabled(false); addStockDatabaseAction.setEnabled(false); removeStockDatabaseAction.setEnabled(false); startAutoUpdateAction.setEnabled(false); stopAutoUpdateAction.setEnabled(false); } } } }); dataManagerTree.addDoubleClickListener(new IDoubleClickListener() { @Override public void doubleClick(DoubleClickEvent event) { ISelection selection = event.getSelection(); if (selection instanceof IStructuredSelection) { IStructuredSelection structuredSelection = (IStructuredSelection) selection; Object o = structuredSelection.getFirstElement(); if (o instanceof StockDatabasePresentationWrapper) { StockDatabasePresentationWrapper selectedStockDatabase = (StockDatabasePresentationWrapper) o; try { getSite().getPage().showView(StockDatabaseChartView.MULTI_STOCK_DB_VIEW_ID, selectedStockDatabase.getPrettyName(), IWorkbenchPage.VIEW_VISIBLE); } catch (PartInitException e) { MessageDialog.openError(MarketDataManagersView.this.parent.getShell(), "Error", "A problem occurred while opening view for: " + selectedStockDatabase.getPrettyName() + "[" + LangUtils.exceptionMessage(e) + "]"); } } } } }); getSite().setSelectionProvider(dataManagerTree); hookGlobalActions(); createContextMenu(); }