KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ui > dialogs > ResourceMappingHierarchyArea


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.team.internal.ui.dialogs;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
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 JavaDoc TEAM_NAVIGATOR_CONTENT = "org.eclipse.team.ui.navigatorViewer"; //$NON-NLS-1$
32
private String JavaDoc 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 JavaDoc[] objects = getRootModelObjects();
71         viewer.setSelection(new StructuredSelection(objects), true);
72     }
73
74     private Object JavaDoc getInitialInput() {
75         if (context != null)
76             return context;
77         return scope;
78     }
79
80     private Object JavaDoc[] getRootModelObjects() {
81         if (scope == null)
82             return new Object JavaDoc[0];
83         ResourceMapping[] mappings = scope.getMappings();
84         List JavaDoc result = new ArrayList JavaDoc();
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 JavaDoc[result.size()]);
90     }
91
92     public void setDescription(String JavaDoc string) {
93         description = string;
94     }
95
96     /* (non-Javadoc)
97      * @see org.eclipse.ui.navigator.internal.extensions.INavigatorContentServiceListener#onLoad(org.eclipse.ui.navigator.internal.extensions.NavigatorContentExtension)
98      */

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