KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > AddToVersionControlDialog


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;
12
13 import java.util.Arrays JavaDoc;
14 import java.util.List JavaDoc;
15
16 import org.eclipse.core.resources.IResource;
17 import org.eclipse.jface.dialogs.IDialogConstants;
18 import org.eclipse.jface.viewers.*;
19 import org.eclipse.osgi.util.NLS;
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.events.*;
22 import org.eclipse.swt.layout.GridData;
23 import org.eclipse.swt.layout.GridLayout;
24 import org.eclipse.swt.widgets.*;
25 import org.eclipse.team.internal.ui.dialogs.DetailsDialog;
26 import org.eclipse.ui.model.WorkbenchContentProvider;
27 import org.eclipse.ui.model.WorkbenchLabelProvider;
28
29 /**
30  * This dialog allows the user to add a set of resources to version control.
31  * They can either all be added or the user can choose which to add from a
32  * details list.
33  */

34 public class AddToVersionControlDialog extends DetailsDialog {
35
36     private static final int WIDTH_HINT = 350;
37     private final static int SELECTION_HEIGHT_HINT = 100;
38     
39     private IResource[] unaddedResources;
40     private Object JavaDoc[] resourcesToAdd;
41     
42     private CheckboxTableViewer listViewer;
43     /**
44      * Constructor for AddToVersionControlDialog.
45      * @param parentShell
46      */

47     public AddToVersionControlDialog(Shell parentShell, IResource[] unaddedResources) {
48         super(parentShell, CVSUIMessages.AddToVersionControlDialog_title);
49         this.unaddedResources = unaddedResources;
50     }
51
52     /**
53      * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
54      */

55     protected void createMainDialogArea(Composite parent) {
56         Composite composite = new Composite(parent, SWT.NULL);
57         composite.setLayout(new GridLayout());
58         composite.setLayoutData(new GridData(GridData.FILL_BOTH));
59              
60         // add a description label
61
if (unaddedResources.length==1) {
62             createWrappingLabel(composite, NLS.bind(CVSUIMessages.AddToVersionControlDialog_thereIsAnUnaddedResource, new String JavaDoc[] { new Integer JavaDoc(unaddedResources.length).toString() }));
63         } else {
64             createWrappingLabel(composite, NLS.bind(CVSUIMessages.AddToVersionControlDialog_thereAreUnaddedResources, new String JavaDoc[] { new Integer JavaDoc(unaddedResources.length).toString() }));
65         }
66     }
67
68     /* (non-Javadoc)
69      * @see org.eclipse.team.internal.ui.dialogs.DetailsDialog#getHelpContextId()
70      */

71     protected String JavaDoc getHelpContextId() {
72         return IHelpContextIds.ADD_TO_VERSION_CONTROL_DIALOG;
73     }
74
75     /**
76      * @see org.eclipse.team.internal.ui.DetailsDialog#createDropDownDialogArea(org.eclipse.swt.widgets.Composite)
77      */

78     protected Composite createDropDownDialogArea(Composite parent) {
79         // create a composite with standard margins and spacing
80
Composite composite = new Composite(parent, SWT.NONE);
81         GridLayout layout = new GridLayout();
82         layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
83         layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
84         layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
85         layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
86         composite.setLayout(layout);
87         composite.setLayoutData(new GridData(GridData.FILL_BOTH));
88         
89         addUnaddedResourcesArea(composite);
90         
91         return composite;
92     }
93
94     private void addUnaddedResourcesArea(Composite composite) {
95         
96         // add a description label
97
createWrappingLabel(composite, CVSUIMessages.ReleaseCommentDialog_unaddedResources);
98     
99         // add the selectable checkbox list
100
listViewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER);
101         GridData data = new GridData(GridData.FILL_BOTH);
102         data.heightHint = SELECTION_HEIGHT_HINT;
103         data.widthHint = WIDTH_HINT;
104         listViewer.getTable().setLayoutData(data);
105
106         // set the contents of the list
107
listViewer.setLabelProvider(new WorkbenchLabelProvider() {
108             protected String JavaDoc decorateText(String JavaDoc input, Object JavaDoc element) {
109                 if (element instanceof IResource)
110                     return ((IResource)element).getFullPath().toString();
111                 else
112                     return input;
113             }
114         });
115         listViewer.setContentProvider(new WorkbenchContentProvider());
116         listViewer.setInput(new AdaptableResourceList(unaddedResources));
117         if (resourcesToAdd == null) {
118             listViewer.setAllChecked(true);
119         } else {
120             listViewer.setCheckedElements(resourcesToAdd);
121         }
122         listViewer.addSelectionChangedListener(new ISelectionChangedListener() {
123             public void selectionChanged(SelectionChangedEvent event) {
124                 resourcesToAdd = listViewer.getCheckedElements();
125             }
126         });
127         
128         addSelectionButtons(composite);
129     }
130     
131     /**
132      * Add the selection and deselection buttons to the dialog.
133      * @param composite org.eclipse.swt.widgets.Composite
134      */

135     private void addSelectionButtons(Composite composite) {
136     
137         Composite buttonComposite = new Composite(composite, SWT.RIGHT);
138         GridLayout layout = new GridLayout();
139         layout.numColumns = 2;
140         buttonComposite.setLayout(layout);
141         GridData data =
142             new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.GRAB_HORIZONTAL);
143         data.grabExcessHorizontalSpace = true;
144         composite.setData(data);
145     
146         Button selectButton = createButton(buttonComposite, IDialogConstants.SELECT_ALL_ID, CVSUIMessages.ReleaseCommentDialog_selectAll, false);
147         SelectionListener listener = new SelectionAdapter() {
148             public void widgetSelected(SelectionEvent e) {
149                 listViewer.setAllChecked(true);
150                 resourcesToAdd = null;
151             }
152         };
153         selectButton.addSelectionListener(listener);
154     
155         Button deselectButton = createButton(buttonComposite, IDialogConstants.DESELECT_ALL_ID, CVSUIMessages.ReleaseCommentDialog_deselectAll, false);
156         listener = new SelectionAdapter() {
157             public void widgetSelected(SelectionEvent e) {
158                 listViewer.setAllChecked(false);
159                 resourcesToAdd = new Object JavaDoc[0];
160     
161             }
162         };
163         deselectButton.addSelectionListener(listener);
164     }
165     
166     /**
167      * @see org.eclipse.team.internal.ui.DetailsDialog#updateEnablements()
168      */

169     protected void updateEnablements() {
170     }
171     
172     /**
173      * Returns the resourcesToAdd.
174      * @return IResource[]
175      */

176     public IResource[] getResourcesToAdd() {
177         if (resourcesToAdd == null) {
178             return unaddedResources;
179         } else {
180             List JavaDoc result = Arrays.asList(resourcesToAdd);
181             return (IResource[]) result.toArray(new IResource[result.size()]);
182         }
183     }
184     
185     /* (non-Javadoc)
186      * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
187      */

188     protected void createButtonsForButtonBar(Composite parent) {
189         createButton(parent, IDialogConstants.YES_ID, IDialogConstants.YES_LABEL, true);
190         createButton(parent, IDialogConstants.NO_ID, IDialogConstants.NO_LABEL, true);
191         super.createButtonsForButtonBar(parent);
192     }
193     
194     /* (non-Javadoc)
195      * @see org.eclipse.team.internal.ui.DetailsDialog#includeOkButton()
196      */

197     protected boolean includeOkButton() {
198         return false;
199     }
200     /* (non-Javadoc)
201      * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
202      */

203     protected void buttonPressed(int id) {
204         // hijack yes and no buttons to set the correct return
205
// codes.
206
if(id == IDialogConstants.YES_ID || id == IDialogConstants.NO_ID) {
207             setReturnCode(id);
208             close();
209         } else {
210             super.buttonPressed(id);
211         }
212     }
213 }
214
Popular Tags