1 11 package org.eclipse.team.internal.ui.synchronize; 12 13 import java.util.ArrayList ; 14 import java.util.Arrays ; 15 import java.util.List ; 16 17 import org.eclipse.core.resources.IContainer; 18 import org.eclipse.core.resources.IResource; 19 import org.eclipse.jface.viewers.*; 20 import org.eclipse.swt.SWT; 21 import org.eclipse.swt.graphics.Image; 22 import org.eclipse.swt.layout.GridData; 23 import org.eclipse.swt.widgets.Composite; 24 import org.eclipse.team.internal.ui.TeamUIMessages; 25 import org.eclipse.team.ui.synchronize.*; 26 import org.eclipse.ui.IWorkingSet; 27 import org.eclipse.ui.PlatformUI; 28 import org.eclipse.ui.dialogs.ContainerCheckedTreeViewer; 29 import org.eclipse.ui.ide.IDE; 30 import org.eclipse.ui.model.BaseWorkbenchContentProvider; 31 import org.eclipse.ui.model.WorkbenchLabelProvider; 32 import org.eclipse.ui.views.navigator.ResourceSorter; 33 34 42 public class GlobalRefreshResourceSelectionPage extends GlobalRefreshElementSelectionPage { 43 44 private List resources; 45 46 50 class MyContentProvider extends BaseWorkbenchContentProvider { 51 public Object [] getChildren(Object element) { 52 if(element instanceof List ) { 53 return (IResource[]) ((List )element).toArray(new IResource[((List )element).size()]); 54 } 55 return super.getChildren(element); 56 } 57 } 58 59 63 class MyLabelProvider extends LabelProvider { 64 private LabelProvider workbenchProvider = new WorkbenchLabelProvider(); 65 public String getText(Object element) { 66 if(element instanceof IContainer) { 67 IContainer c = (IContainer)element; 68 if(c.getType() != IResource.PROJECT && resources.contains(c)) { 69 return c.getFullPath().toString(); 70 } 71 } 72 return workbenchProvider.getText(element); 73 } 74 public Image getImage(Object element) { 75 return workbenchProvider.getImage(element); 76 } 77 } 78 79 84 public GlobalRefreshResourceSelectionPage(IResource[] resources) { 85 super(TeamUIMessages.GlobalRefreshResourceSelectionPage_1); 86 this.resources = Arrays.asList(resources); 88 setDescription(TeamUIMessages.GlobalRefreshResourceSelectionPage_2); 89 setTitle(TeamUIMessages.GlobalRefreshResourceSelectionPage_3); 90 } 91 92 protected ContainerCheckedTreeViewer createViewer(Composite top) { 93 GridData data; 94 ContainerCheckedTreeViewer fViewer = new ContainerCheckedTreeViewer(top, SWT.BORDER); 95 data = new GridData(GridData.FILL_BOTH); 96 data.heightHint = 100; 98 fViewer.getControl().setLayoutData(data); 99 fViewer.setContentProvider(new MyContentProvider()); 100 fViewer.setLabelProvider(new DecoratingLabelProvider(new MyLabelProvider(), PlatformUI.getWorkbench().getDecoratorManager().getLabelDecorator())); 101 fViewer.addCheckStateListener(new ICheckStateListener() { 102 103 public void checkStateChanged(CheckStateChangedEvent event) { 104 updateOKStatus(); 105 } 106 }); 107 fViewer.setSorter(new ResourceSorter(ResourceSorter.NAME)); 108 fViewer.setInput(resources); 109 return fViewer; 110 } 111 112 protected void checkAll() { 113 getViewer().setCheckedElements(resources.toArray()); 114 } 115 116 protected boolean checkWorkingSetElements() { 117 List allWorkingSetResources = new ArrayList (); 118 IWorkingSet[] workingSets = getWorkingSets(); 119 for (int i = 0; i < workingSets.length; i++) { 120 IWorkingSet set = workingSets[i]; 121 allWorkingSetResources.addAll(IDE.computeSelectedResources(new StructuredSelection(set.getElements()))); 122 } 123 getViewer().setCheckedElements(allWorkingSetResources.toArray(new IResource[allWorkingSetResources.size()])); 124 return !allWorkingSetResources.isEmpty(); 125 } 126 127 public IResource[] getRootResources() { 128 Object [] objects = getRootElement(); 129 IResource[] resources = new IResource[objects.length]; 130 for (int i = 0; i < resources.length; i++) { 131 resources[i] = (IResource)objects[i]; 132 133 } 134 return resources; 135 } 136 137 public ISynchronizeScope getSynchronizeScope() { 138 if (isWorkingSetSelected()) { 139 return new WorkingSetScope(getWorkingSets()); 140 } 141 if (isWorkspaceSelected()) { 142 return new WorkspaceScope(); 143 } 144 return new ResourceScope(getRootResources()); 145 } 146 147 } 148 | Popular Tags |