/** * @param aContentService * @param descriptor * @return True if the descriptor is visible to the given content service. */ private boolean isVisible( INavigatorContentService aContentService, CommonWizardDescriptor descriptor) { return !WorkbenchActivityHelper.filterItem(descriptor) && (aContentService == null || (descriptor.getId() == null || (aContentService.isVisible(descriptor.getId()) && aContentService.isActive(descriptor.getId())))); }
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); }
/* * (non-Javadoc) * @see org.eclipse.jface.action.Action#run() */ @Override public void run() { Set<String> activeIds = new HashSet<String>(); String[] visibleIds = contentService.getVisibleExtensionIds(); if (visibleIds != null) { for (String visibleId : visibleIds) { if (contentService.isActive(visibleId)) activeIds.add(visibleId); } } if (isChecked()) activeIds.add(contentDescriptor.getId()); else activeIds.remove(contentDescriptor.getId()); String[] idsToActivate = activeIds.toArray(new String[activeIds.size()]); UpdateActiveExtensionsOperation updateExtensions = new UpdateActiveExtensionsOperation(commonViewer, idsToActivate); updateExtensions.execute(null, null); }
/* * (non-Javadoc) * @see org.eclipse.ui.actions.CompoundContributionItem#getContributionItems() */ @Override protected IContributionItem[] getContributionItems() { CommonNavigator navigator = (CommonNavigator) ViewsUtil.getPart(IUIConstants.ID_EXPLORER); if (navigator == null) return new IContributionItem[0]; INavigatorContentService contentService = navigator.getNavigatorContentService(); List<IContributionItem> items = new ArrayList<IContributionItem>(); List<String> extensionSet = new MRUList(IPreferenceKeys.PREF_CONTENT_MRU_LIST); CommonViewer commonViewer = navigator.getCommonViewer(); for (int i = 0; i < extensionSet.size(); i++) { String extensionId = extensionSet.get(i); INavigatorContentDescriptor contentDescriptor = contentService.getContentDescriptorById(extensionId); if (contentDescriptor != null) { items.add( new ActionContributionItem( new ContentMRUAction((i + 1), contentDescriptor, contentService, commonViewer))); } } return items.toArray(new IContributionItem[items.size()]); }
/** Constructor */ public ContentMRUAction( int order, INavigatorContentDescriptor contentDescriptor, INavigatorContentService contentService, CommonViewer commonViewer) { super( "" + order + " " + contentDescriptor.getName(), AS_CHECK_BOX); // $NON-NLS-1$//$NON-NLS-2$ this.contentDescriptor = contentDescriptor; this.contentService = contentService; this.commonViewer = commonViewer; setChecked(contentService.isActive(contentDescriptor.getId())); }
/** {@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; }