1 11 package org.eclipse.team.internal.ui.dialogs; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 15 16 import org.eclipse.core.resources.mapping.ResourceMapping; 17 import org.eclipse.jface.viewers.StructuredSelection; 18 import org.eclipse.swt.SWT; 19 import org.eclipse.swt.layout.GridData; 20 import org.eclipse.swt.layout.GridLayout; 21 import org.eclipse.swt.widgets.Composite; 22 import org.eclipse.team.core.mapping.ISynchronizationContext; 23 import org.eclipse.team.core.mapping.ISynchronizationScope; 24 import org.eclipse.team.internal.ui.mapping.TeamViewerSorter; 25 import org.eclipse.team.ui.TeamUI; 26 import org.eclipse.team.ui.mapping.ITeamContentProviderManager; 27 import org.eclipse.ui.navigator.*; 28 29 public class ResourceMappingHierarchyArea extends DialogArea implements INavigatorContentServiceListener { 30 31 private static final String TEAM_NAVIGATOR_CONTENT = "org.eclipse.team.ui.navigatorViewer"; private String description; 33 private CommonViewer viewer; 34 private final ISynchronizationScope scope; 35 private final ISynchronizationContext context; 36 37 38 public static ResourceMappingHierarchyArea create(ISynchronizationScope scope, ISynchronizationContext context) { 39 return new ResourceMappingHierarchyArea(scope, context); 40 } 41 42 private ResourceMappingHierarchyArea(ISynchronizationScope scope, ISynchronizationContext context) { 43 this.scope = scope; 44 this.context = context; 45 } 46 47 public void createArea(Composite parent) { 48 Composite composite = new Composite(parent, SWT.NULL); 49 GridLayout layout = new GridLayout(1, false); 50 layout.marginHeight = 0; 51 layout.marginWidth = 0; 52 composite.setLayout(layout); 53 composite.setLayoutData(new GridData(GridData.FILL_BOTH)); 54 55 if (description != null) 56 createWrappingLabel(composite, description, 1); 57 58 viewer = new CommonViewer(TEAM_NAVIGATOR_CONTENT, composite, SWT.BORDER); 59 viewer.setSorter(new CommonViewerSorter()); 60 viewer.setSorter(new TeamViewerSorter((CommonViewerSorter)viewer.getSorter())); 61 viewer.getNavigatorContentService().bindExtensions(TeamUI.getTeamContentProviderManager().getContentProviderIds(scope), true); 62 viewer.getNavigatorContentService().getActivationService().activateExtensions(TeamUI.getTeamContentProviderManager().getContentProviderIds(scope), true); 63 GridData data = new GridData(GridData.FILL_BOTH); 64 data.heightHint = 100; 65 data.widthHint = 300; 66 viewer.getControl().setLayoutData(data); 67 viewer.getNavigatorContentService().addListener(this); 68 viewer.setInput(getInitialInput()); 69 viewer.refresh(); 70 Object [] objects = getRootModelObjects(); 71 viewer.setSelection(new StructuredSelection(objects), true); 72 } 73 74 private Object getInitialInput() { 75 if (context != null) 76 return context; 77 return scope; 78 } 79 80 private Object [] getRootModelObjects() { 81 if (scope == null) 82 return new Object [0]; 83 ResourceMapping[] mappings = scope.getMappings(); 84 List result = new ArrayList (); 85 for (int i = 0; i < mappings.length; i++) { 86 ResourceMapping mapping = mappings[i]; 87 result.add(mapping.getModelObject()); 88 } 89 return result.toArray(new Object [result.size()]); 90 } 91 92 public void setDescription(String string) { 93 description = string; 94 } 95 96 99 public void onLoad(INavigatorContentExtension anExtension) { 100 anExtension.getStateModel().setProperty(ITeamContentProviderManager.P_SYNCHRONIZATION_SCOPE, scope); 101 if (context != null) { 102 anExtension.getStateModel().setProperty(ITeamContentProviderManager.P_SYNCHRONIZATION_CONTEXT, context); 103 } 104 } 105 106 } 107 | Popular Tags |