public void hookOnViewer(final String viewerId) { IWorkbench workbench = PlatformUI.getWorkbench(); if (viewerId != null && workbench != null && workbench.getDisplay() != null) { Display display = workbench.getDisplay(); Thread displayThread = display.getThread(); if (workbench.isStarting() || !Thread.currentThread().equals(displayThread)) { // while workbench is starting defer hooking until later UIJob job = new UIJob(display, "viewer hooker") { @Override public IStatus runInUIThread(IProgressMonitor monitor) { hookOnViewer(viewerId); return Status.OK_STATUS; } }; job.schedule(250); } else if (viewerId != null) { CommonNavigator navigator = (CommonNavigator) eu.fittest.eclipse.gui.utils.Viewer.getView(viewerId); if (navigator != null) { CommonViewer viewer = navigator.getCommonViewer(); if (viewer != null) { if (this.viewer != null) { this.viewer.removeSelectionChangedListener(this); } requestRefresh(); viewer.addSelectionChangedListener(this); this.viewer = viewer; } } } } }
@Override public Object execute(ExecutionEvent event) throws ExecutionException { HandlerUtil.toggleCommandState(event.getCommand()); IWorkbenchPart part = HandlerUtil.getActivePartChecked(event); if (part instanceof RepositoriesView) { CommonViewer viewer = ((RepositoriesView) part).getCommonViewer(); viewer.refresh(); } return null; }
/** Take the server combo's selection and apply it to the viewer */ private void handleServerComboSelection() { TeiidEmptyNode emptyNode = new TeiidEmptyNode(); // populate viewer String serverName = jbossServerCombo.getText(); IServer server = serverMap.get(serverName); if (server == null) { viewer.setInput(emptyNode); } else { viewer.setInput(server); } // Ensures that the action provider is properly initialised in this view IStructuredSelection selection = new StructuredSelection(emptyNode); getNavigatorActionService().setContext(new ActionContext(selection)); getNavigatorActionService().fillActionBars(getViewSite().getActionBars()); }
public void run(IAction action) { if (navigator == null) { return; } Grouping grouping = getGrouping(action.getId()); if (grouping == null) { return; } BugContentProvider provider = BugContentProvider.getProvider(navigator.getNavigatorContentService()); provider.setGrouping(grouping); CommonViewer viewer = navigator.getCommonViewer(); Object[] expandedElements = viewer.getExpandedElements(); provider.reSetInput(); viewer.setExpandedElements(expandedElements); }
public static IFolder getFolder() { CommonNavigator navigator = (CommonNavigator) Viewer.getView(IFITTESTFolderConstants.NAVIGATOR); if (navigator != null) { CommonViewer viewer = navigator.getCommonViewer(); if (viewer != null) { ISelection selection = viewer.getSelection(); if (selection instanceof IStructuredSelection && !selection.isEmpty()) { IStructuredSelection sel = (IStructuredSelection) selection; Object object = sel.getFirstElement(); return (object instanceof IFolder && !(object instanceof IProject)) ? (IFolder) object : null; } } } return null; }
private static void processContentExtensions( final CommonViewer commonViewer, boolean activeFilter, boolean activedPerspectiveFilter) { final INavigatorContentService contentService = commonViewer.getNavigatorContentService(); String[] visibleExtensionIds = contentService.getVisibleExtensionIds(); List<String> visibleIDsForPecpective = new ArrayList<String>(); List<String> visibleIdsForActiveFilter = new ArrayList<String>(); if (visibleExtensionIds != null) { visibleIdsForActiveFilter.addAll(Arrays.asList(visibleExtensionIds)); } if (activedPerspectiveFilter) { String perspectiveId = PlatformUI.getWorkbench() .getActiveWorkbenchWindow() .getActivePage() .getPerspective() .getId(); PerspectiveFilterHelper helper = new PerspectiveFilterHelper(); helper.setTreeViewer(commonViewer); helper.setNavigatorContentService(contentService); helper.setActionProviderId(PerspectiveFilterActionProvider.ID); String[] pvExtensions = helper.getExtensionIdsToActivate(perspectiveId); if (pvExtensions != null && pvExtensions.length > 0) { visibleIDsForPecpective = Arrays.asList(pvExtensions); } visibleIdsForActiveFilter.retainAll(visibleIDsForPecpective); } String[] filteredContents = RepositoryNodeFilterHelper.getFilterByNodeValues(); List<String> filteredContentsList = new ArrayList<String>(); if (filteredContents != null) { filteredContentsList = Arrays.asList(filteredContents); } List<String> checkedExtensions = new ArrayList<String>(); if (activeFilter) { for (String id : visibleIdsForActiveFilter) { if (!filteredContentsList.contains(id)) { checkedExtensions.add(id); } } } else { checkedExtensions.addAll(visibleIdsForActiveFilter); } String[] contentExtensionIdsToActivate = (String[]) checkedExtensions.toArray(new String[checkedExtensions.size()]); UpdateActiveExtensionsOperation updateExtensions = new UpdateActiveExtensionsOperation(commonViewer, contentExtensionIdsToActivate); updateExtensions.execute(null, null); }
/** {@inheritDoc} */ public Object execute(ExecutionEvent event) throws ExecutionException { if (getCommonNavigator() == null || getCommonNavigator().getCommonViewer() == null) { return null; // The model explorer is not displayed (The editor is closed?) } CommonViewer viewer = getCommonNavigator().getCommonViewer(); String[] newContents = null; Object trigger = event.getTrigger(); if (trigger instanceof Event) { // State based on the widget Event triggerEvent = (Event) trigger; if (triggerEvent.widget instanceof ToolItem) { if (((ToolItem) triggerEvent.widget).getSelection()) { newContents = new String[] {DIAGRAM_CONTENTS}; } else { newContents = new String[] {UML_MODEL_CONTENTS}; } } } if (newContents == null) { // Revert the current state INavigatorContentService navigatorContent = viewer.getNavigatorContentService(); if (navigatorContent.isActive(DIAGRAM_CONTENTS)) { newContents = new String[] {UML_MODEL_CONTENTS}; } else { newContents = new String[] {DIAGRAM_CONTENTS}; } } UpdateActiveExtensionsOperation updateExtensions = new UpdateActiveExtensionsOperation(viewer, newContents); updateExtensions.execute(null, null); return null; }
@Test public void testFilter() throws CoreException { IPerspectiveDescriptor persDescription = PlatformUI.getWorkbench() .getPerspectiveRegistry() .findPerspectiveWithId(JavaUI.ID_PERSPECTIVE); IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); page.setPerspective(persDescription); IViewPart arquilliaView = page.showView(ArquillianView.ID); try { assertTrue(arquilliaView instanceof CommonNavigator); PackageExplorerPart packageView = (PackageExplorerPart) page.showView(JavaUI.ID_PACKAGES); IProject project = getProject(TEST_PROJECT_NAME); packageView.selectAndReveal(project); CommonNavigator navigator = (CommonNavigator) arquilliaView; CommonViewer viewer = navigator.getCommonViewer(); TreeItem[] items = viewer.getTree().getItems(); assertTrue(items.length == 1); ViewerFilter[] filters = viewer.getFilters(); assertTrue(filters.length > 0); WorkingSetFilter activeFilter = null; List<ViewerFilter> newFilters = new ArrayList<ViewerFilter>(); int i = 0; for (ViewerFilter filter : filters) { if (!(filter instanceof ActiveProjectFilter)) { newFilters.add(filter); } } newFilters.add(new WorkingSetFilter()); viewer.setFilters(newFilters.toArray(new ViewerFilter[0])); items = viewer.getTree().getItems(); assertTrue("Invalid filter", items.length == 2); } finally { if (arquilliaView != null) { page.hideView(arquilliaView); } } }
private static void processCommonFilters(final CommonViewer commonViewer, boolean activedFilter) { // final ICommonFilterDescriptor[] visibleFilterDescriptors = // commonViewer.getNavigatorContentService().getFilterService() // .getVisibleFilterDescriptors(); // // String[] filters = new String[visibleFilterDescriptors.length]; // // for (int i = 0; i < visibleFilterDescriptors.length; i++) { // final String id = visibleFilterDescriptors[i].getId(); // filters[i] = id; // } // UpdateActiveFiltersOperation updateFilters = new UpdateActiveFiltersOperation(commonViewer, // filters); // updateFilters.execute(null, null); INavigatorFilterService filterService = commonViewer.getNavigatorContentService().getFilterService(); if (filterService instanceof NavigatorFilterService) { ((NavigatorFilterService) filterService).updateViewer(); } }
public void run(IAction action) { if (navigator != null) { CommonViewer viewer = navigator.getCommonViewer(); BugContentProvider provider = BugContentProvider.getProvider(navigator.getNavigatorContentService()); // provider.setRefreshRequested(true); Object[] expandedElements = viewer.getExpandedElements(); Object input = viewer.getInput(); if (provider.getChildren(input).length == 0) { viewer.setInput(null); if (input instanceof IWorkingSet || input instanceof IWorkspaceRoot) { viewer.setInput(input); } else { viewer.setInput(ResourcesPlugin.getWorkspace().getRoot()); } viewer.refresh(true); } else { provider.reSetInput(); } viewer.setExpandedElements(expandedElements); } }
/** Passing the focus request to the viewer's control. */ @Override public void setFocus() { viewer.getControl().setFocus(); }
/** This is a callback that will allow us to create the viewer and initialize it. */ @Override public void createPartControl(Composite parent) { FormToolkit toolkit = new FormToolkit(parent.getDisplay()); Composite frame = toolkit.createComposite(parent, SWT.BORDER); GridLayoutFactory.fillDefaults().numColumns(2).applyTo(frame); Composite comboDescFrame = toolkit.createComposite(frame, SWT.NONE); GridDataFactory.fillDefaults().applyTo(comboDescFrame); GridLayoutFactory.fillDefaults() .margins(5, 20) .spacing(SWT.DEFAULT, 25) .applyTo(comboDescFrame); Composite comboFrame = toolkit.createComposite(comboDescFrame, SWT.NONE); GridDataFactory.fillDefaults().applyTo(comboFrame); GridLayoutFactory.fillDefaults().applyTo(comboFrame); Composite labelFrame = toolkit.createComposite(comboFrame, SWT.NONE); GridDataFactory.fillDefaults().applyTo(labelFrame); GridLayoutFactory.fillDefaults().numColumns(2).equalWidth(false).applyTo(labelFrame); Label jbLabel = WidgetFactory.createLabel( labelFrame, UTIL.getString("TeiidServerOverviewSection.jbLabel")); // $NON-NLS-1$ jbLabel.setForeground(labelFrame.getDisplay().getSystemColor(SWT.COLOR_DARK_BLUE)); GridDataFactory.swtDefaults().grab(false, false).applyTo(jbLabel); newServerOrOpenServerViewHyperlink = toolkit.createHyperlink(labelFrame, EDIT_SERVER_LABEL, SWT.NONE); GridDataFactory.swtDefaults().applyTo(newServerOrOpenServerViewHyperlink); newServerOrOpenServerViewHyperlink.addHyperlinkListener( new HyperlinkAdapter() { @Override public void linkActivated(HyperlinkEvent e) { if (serverMap.isEmpty()) { // There are no servers so open the server wizard NewServerAction action = new NewServerAction(getViewSite().getShell(), getServerManager()); action.run(); } else { // open the servers view IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); try { window .getActivePage() .showView("org.eclipse.wst.server.ui.ServersView"); // $NON-NLS-1$ } catch (PartInitException ex) { UTIL.log(ex); } } } }); jbossServerCombo = new Combo(comboFrame, SWT.READ_ONLY | SWT.DROP_DOWN); toolkit.adapt(jbossServerCombo); GridDataFactory.swtDefaults().minSize(250, 30).grab(true, false).applyTo(jbossServerCombo); jbossServerCombo.addSelectionListener( new SelectionListener() { @Override public void widgetSelected(SelectionEvent e) { handleServerComboSelection(); } @Override public void widgetDefaultSelected(SelectionEvent e) { handleServerComboSelection(); } }); Text descriptionText = toolkit.createText( comboDescFrame, UTIL.getString("TeiidServerOverviewSection.description"), // $NON-NLS-1$ SWT.MULTI | SWT.WRAP); descriptionText.setForeground(comboDescFrame.getDisplay().getSystemColor(SWT.COLOR_DARK_BLUE)); GridDataFactory.fillDefaults() .grab(false, true) .hint(100, SWT.DEFAULT) .applyTo(descriptionText); super.createPartControl(frame); viewer = getCommonViewer(); GridDataFactory.fillDefaults().grab(true, true).applyTo(viewer.getControl()); viewer.setSorter(new NameSorter()); DqpPlugin.getInstance().getServersProvider().addServerLifecycleListener(serversListener); // Populate the jboss server combo box which // should also populate the viewer as well populateJBossServerCombo(); viewer.expandToLevel(3); }