KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > repo > RefreshRemoteProjectSelectionPage


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.ccvs.ui.repo;
12
13 import java.util.Arrays JavaDoc;
14
15 import org.eclipse.core.runtime.IAdaptable;
16 import org.eclipse.jface.dialogs.Dialog;
17 import org.eclipse.jface.dialogs.IDialogSettings;
18 import org.eclipse.jface.resource.ImageDescriptor;
19 import org.eclipse.jface.util.IPropertyChangeListener;
20 import org.eclipse.jface.util.PropertyChangeEvent;
21 import org.eclipse.swt.SWT;
22 import org.eclipse.swt.layout.GridLayout;
23 import org.eclipse.swt.widgets.Composite;
24 import org.eclipse.team.internal.ccvs.core.ICVSRemoteResource;
25 import org.eclipse.team.internal.ccvs.core.ICVSRepositoryLocation;
26 import org.eclipse.team.internal.ccvs.ui.*;
27 import org.eclipse.team.internal.ccvs.ui.model.RemoteContentProvider;
28 import org.eclipse.team.internal.ccvs.ui.wizards.CVSWizardPage;
29 import org.eclipse.ui.IWorkingSet;
30 import org.eclipse.ui.PlatformUI;
31 import org.eclipse.ui.model.IWorkbenchAdapter;
32 import org.eclipse.ui.model.WorkbenchLabelProvider;
33
34 /**
35  * Page that allows the user to select the remote projects whose tags should be
36  * refreshed.
37  */

38 public class RefreshRemoteProjectSelectionPage extends CVSWizardPage {
39     
40     private ICVSRemoteResource[] rootFolders;
41     private ListSelectionArea listArea;
42     private WorkingSetSelectionArea workingSetArea;
43     private IWorkingSet workingSet;
44     private IDialogSettings settings;
45
46     /**
47      * Custom input provider which returns the list of root folders
48      */

49     private class InputElement implements IWorkbenchAdapter, IAdaptable {
50         public Object JavaDoc[] getChildren(Object JavaDoc o) {
51             return rootFolders;
52         }
53         public ImageDescriptor getImageDescriptor(Object JavaDoc object) {
54             return null;
55         }
56         public String JavaDoc getLabel(Object JavaDoc o) {
57             return null;
58         }
59         public Object JavaDoc getParent(Object JavaDoc o) {
60             return null;
61         }
62         public Object JavaDoc getAdapter(Class JavaDoc adapter) {
63             if (adapter == IWorkbenchAdapter.class) return this;
64             return null;
65         }
66     }
67     
68     /**
69      * Constructor for RemoteProjectSelectionPage.
70      * @param pageName
71      * @param title
72      * @param titleImage
73      * @param description
74      */

75     public RefreshRemoteProjectSelectionPage(
76             String JavaDoc pageName,
77             String JavaDoc title,
78             ImageDescriptor titleImage,
79             String JavaDoc description,
80             IDialogSettings settings,
81             ICVSRepositoryLocation root,
82             ICVSRemoteResource[] rootFolders) {
83         super(pageName, title, titleImage, description);
84         this.settings = settings;
85         this.rootFolders = rootFolders;
86     }
87
88     /**
89      * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
90      */

91     public void createControl(Composite parent) {
92         
93         final Composite composite = new Composite(parent, SWT.NONE);
94         composite.setLayout(new GridLayout(1, false));
95         
96         setControl(composite);
97         
98         // set F1 help
99
PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.REFRESH_REMOTE_PROJECT_SELECTION_PAGE);
100         
101         listArea = new ListSelectionArea(
102             new InputElement(),
103             new RemoteContentProvider(),
104             new WorkbenchLabelProvider(),
105             CVSUIMessages.RefreshRemoteProjectSelectionPage_selectRemoteProjects);
106         listArea.createArea(composite);
107
108         listArea.addPropertyChangeListener(new IPropertyChangeListener() {
109             public void propertyChange(PropertyChangeEvent event) {
110                 updateEnablement();
111             }
112         });
113         listArea.getViewer().setComparator(new RepositoryComparator());
114         
115         workingSetArea = new WorkingSetSelectionArea(getShell(), CVSUIMessages.RefreshRemoteProjectSelectionPage_noWorkingSet, CVSUIMessages.RefreshRemoteProjectSelectionPage_workingSet, settings); //
116
setWorkingSet(workingSet);
117         workingSetArea.addPropertyChangeListener(new IPropertyChangeListener() {
118             public void propertyChange(PropertyChangeEvent event) {
119                 workingSet = (IWorkingSet)event.getNewValue();
120                 handleWorkingSetChange();
121             }
122         });
123         workingSetArea.createArea(composite);
124         Dialog.applyDialogFont(parent);
125     }
126
127     /**
128      * Sets the working set that should be selected in the most recently
129      * used working set list.
130      *
131      * @param workingSet the working set that should be selected.
132      * has to exist in the list returned by
133      * org.eclipse.ui.IWorkingSetManager#getRecentWorkingSets().
134      * Must not be null.
135      */

136     public void setWorkingSet(IWorkingSet workingSet) {
137         this.workingSet = workingSet;
138
139         if (workingSetArea != null) {
140             workingSetArea.setWorkingSet(workingSet);
141         }
142     }
143     
144     private void handleWorkingSetChange() {
145         if (workingSet != null) {
146             // check any projects in the working set
147
listArea.getViewer().setAllChecked(false);
148             RepositoryManager manager = CVSUIPlugin.getPlugin().getRepositoryManager();
149             ICVSRemoteResource[] resources = manager.filterResources(workingSet, rootFolders);
150             for (int i = 0; i < resources.length; i++) {
151                 ICVSRemoteResource resource = resources[i];
152                 listArea.getViewer().setChecked(resource, true);
153             }
154         }
155     }
156     
157     private void updateEnablement() {
158         boolean atLeastOne = listArea.getViewer().getCheckedElements().length > 0;
159         setPageComplete(atLeastOne);
160     }
161     
162     /**
163      * Method getSelectedRemoteProject.
164      * @return ICVSRemoteResource[]
165      */

166     public ICVSRemoteResource[] getSelectedRemoteProject() {
167         Object JavaDoc[] checked = listArea.getViewer().getCheckedElements();
168         return (ICVSRemoteResource[]) Arrays.asList(checked).toArray(new ICVSRemoteResource[checked.length]);
169     }
170 }
171
Popular Tags