1 11 12 package org.eclipse.ui.internal.navigator.filters; 13 14 import java.util.Arrays ; 15 16 import org.eclipse.core.commands.operations.AbstractOperation; 17 import org.eclipse.core.runtime.IAdaptable; 18 import org.eclipse.core.runtime.IProgressMonitor; 19 import org.eclipse.core.runtime.IStatus; 20 import org.eclipse.core.runtime.Status; 21 import org.eclipse.jface.viewers.ISelection; 22 import org.eclipse.jface.viewers.IStructuredSelection; 23 import org.eclipse.jface.viewers.StructuredSelection; 24 import org.eclipse.ui.internal.navigator.CommonNavigatorMessages; 25 import org.eclipse.ui.navigator.CommonViewer; 26 import org.eclipse.ui.navigator.INavigatorContentDescriptor; 27 import org.eclipse.ui.navigator.INavigatorContentService; 28 29 41 public class UpdateActiveExtensionsOperation extends AbstractOperation { 42 43 private String [] contentExtensionsToActivate; 44 45 private final CommonViewer commonViewer; 46 47 private final INavigatorContentService contentService; 48 49 63 public UpdateActiveExtensionsOperation(CommonViewer aCommonViewer, 64 String [] theExtensionsToActivate) { 65 super( 66 CommonNavigatorMessages.UpdateFiltersOperation_Update_CommonViewer_Filter_); 67 commonViewer = aCommonViewer; 68 contentService = commonViewer.getNavigatorContentService(); 69 contentExtensionsToActivate = theExtensionsToActivate; 70 71 } 72 73 79 public IStatus execute(IProgressMonitor monitor, IAdaptable info) { 80 81 boolean updateExtensionActivation = false; 82 83 Arrays.sort(contentExtensionsToActivate); 85 86 IStructuredSelection ssel = null; 87 88 try { 89 commonViewer.getControl().setRedraw(false); 90 91 ISelection selection = commonViewer.getSelection(); 92 if(selection instanceof IStructuredSelection) 93 ssel = (IStructuredSelection) selection; 94 95 INavigatorContentDescriptor[] visibleContentDescriptors = contentService 96 .getVisibleExtensions(); 97 98 int indexofContentExtensionIdToBeActivated; 99 100 for (int i = 0; i < visibleContentDescriptors.length 101 && !updateExtensionActivation; i++) { 102 indexofContentExtensionIdToBeActivated = Arrays.binarySearch( 103 contentExtensionsToActivate, 104 visibleContentDescriptors[i].getId()); 105 109 if (indexofContentExtensionIdToBeActivated >= 0 110 ^ contentService.isActive(visibleContentDescriptors[i] 111 .getId())) { 112 updateExtensionActivation = true; 113 } 114 } 115 116 117 if (updateExtensionActivation) { 118 119 contentService.getActivationService().activateExtensions( 120 contentExtensionsToActivate, true); 121 contentService.getActivationService() 122 .persistExtensionActivations(); 123 124 125 Object [] expandedElements = commonViewer.getExpandedElements(); 126 127 contentService.update(); 128 129 commonViewer.refresh(); 130 131 Object [] originalObjects = ssel.toArray(); 132 133 commonViewer.setExpandedElements(expandedElements); 134 135 IStructuredSelection newSelection = new StructuredSelection(originalObjects); 136 commonViewer.setSelection(newSelection, true); 137 } 138 139 } finally { 140 commonViewer.getControl().setRedraw(true); 141 } 142 143 return Status.OK_STATUS; 144 } 145 146 152 public IStatus redo(IProgressMonitor monitor, IAdaptable info) { 153 return null; 154 } 155 156 162 public IStatus undo(IProgressMonitor monitor, IAdaptable info) { 163 return null; 164 } 165 } 166 | Popular Tags |