KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > team > internal > ccvs > ui > subscriber > SyncInfoSetDetailsDialog


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.subscriber;
12
13 import org.eclipse.core.resources.IResource;
14 import org.eclipse.jface.dialogs.IDialogConstants;
15 import org.eclipse.jface.viewers.*;
16 import org.eclipse.swt.SWT;
17 import org.eclipse.swt.events.*;
18 import org.eclipse.swt.layout.GridData;
19 import org.eclipse.swt.layout.GridLayout;
20 import org.eclipse.swt.widgets.*;
21 import org.eclipse.team.core.synchronize.*;
22 import org.eclipse.team.internal.ccvs.ui.AdaptableResourceList;
23 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages;
24 import org.eclipse.team.internal.ui.dialogs.DetailsDialog;
25 import org.eclipse.ui.model.WorkbenchContentProvider;
26 import org.eclipse.ui.model.WorkbenchLabelProvider;
27
28 /**
29  * DetailsDialog that has a details area which shows the SyncInfos
30  * in a SyncInfoSet.
31  */

32 public abstract class SyncInfoSetDetailsDialog extends DetailsDialog {
33
34     private static final int WIDTH_HINT = 350;
35     private final static int SELECTION_HEIGHT_HINT = 100;
36     
37     private CheckboxTableViewer listViewer;
38     
39     private SyncInfoSet syncSet;
40     private Object JavaDoc[] selectedResources;
41
42     public SyncInfoSetDetailsDialog(Shell parentShell, String JavaDoc dialogTitle, SyncInfoSet syncSet) {
43         super(parentShell, dialogTitle);
44         this.syncSet = syncSet;
45     }
46
47     /* (non-Javadoc)
48      * @see org.eclipse.team.internal.ui.DetailsDialog#createDropDownDialogArea(org.eclipse.swt.widgets.Composite)
49      */

50     protected Composite createDropDownDialogArea(Composite parent) {
51         Composite composite = createComposite(parent);
52                 
53         addResourcesArea(composite);
54         
55         // TODO: set F1 help
56
//WorkbenchHelp.setHelp(composite, IHelpContextIds.ADD_TO_VERSION_CONTROL_DIALOG);
57

58         return composite;
59     }
60
61     /**
62      * @param composite
63      */

64     private void addResourcesArea(Composite composite) {
65         //createWrappingLabel(composite, detailsTitle);
66
// add the selectable checkbox list
67

68         listViewer = CheckboxTableViewer.newCheckList(composite, SWT.BORDER);
69         GridData data = new GridData(GridData.FILL_BOTH);
70         data.heightHint = SELECTION_HEIGHT_HINT;
71         data.widthHint = WIDTH_HINT;
72         listViewer.getTable().setLayoutData(data);
73
74         // set the contents of the list
75
listViewer.setLabelProvider(new WorkbenchLabelProvider() {
76             protected String JavaDoc decorateText(String JavaDoc input, Object JavaDoc element) {
77                 if (element instanceof IResource)
78                     return ((IResource)element).getFullPath().toString();
79                 else
80                     return input;
81             }
82         });
83         listViewer.setContentProvider(new WorkbenchContentProvider());
84         setViewerInput();
85         listViewer.addSelectionChangedListener(new ISelectionChangedListener() {
86             public void selectionChanged(SelectionChangedEvent event) {
87                 selectedResources = listViewer.getCheckedElements();
88             }
89         });
90         
91         addSelectionButtons(composite);
92         
93     }
94     
95     /**
96      * Add the selection and deselection buttons to the dialog.
97      * @param composite org.eclipse.swt.widgets.Composite
98      */

99     private void addSelectionButtons(Composite composite) {
100     
101         Composite buttonComposite = new Composite(composite, SWT.RIGHT);
102         GridLayout layout = new GridLayout();
103         layout.numColumns = 2;
104         buttonComposite.setLayout(layout);
105         GridData data =
106             new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.GRAB_HORIZONTAL);
107         data.grabExcessHorizontalSpace = true;
108         composite.setData(data);
109     
110         Button selectButton = createButton(buttonComposite, IDialogConstants.SELECT_ALL_ID, CVSUIMessages.ReleaseCommentDialog_selectAll, false);
111         SelectionListener listener = new SelectionAdapter() {
112             public void widgetSelected(SelectionEvent e) {
113                 listViewer.setAllChecked(true);
114                 selectedResources = null;
115             }
116         };
117         selectButton.addSelectionListener(listener);
118     
119         Button deselectButton = createButton(buttonComposite, IDialogConstants.DESELECT_ALL_ID, CVSUIMessages.ReleaseCommentDialog_deselectAll, false);
120         listener = new SelectionAdapter() {
121             public void widgetSelected(SelectionEvent e) {
122                 listViewer.setAllChecked(false);
123                 selectedResources = new Object JavaDoc[0];
124     
125             }
126         };
127         deselectButton.addSelectionListener(listener);
128     }
129     
130     protected void setViewerInput() {
131         if (listViewer == null || listViewer.getControl().isDisposed()) return;
132         listViewer.setInput(new AdaptableResourceList(getAllResources()));
133         if (selectedResources == null) {
134             listViewer.setAllChecked(true);
135         } else {
136             listViewer.setCheckedElements(selectedResources);
137         }
138     }
139     
140     /**
141      * Return a list of all the resources that are currently under consideration by the dialog
142      */

143     protected IResource[] getAllResources() {
144         return syncSet.getResources();
145     }
146
147     /*
148      * (non-Javadoc)
149      * @see org.eclipse.team.internal.ui.DetailsDialog#updateEnablements()
150      */

151     protected void updateEnablements() {
152     }
153     
154     /**
155      * @return
156      */

157     public SyncInfoSet getSyncSet() {
158         return syncSet;
159     }
160
161     /* (non-Javadoc)
162      * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
163      */

164     protected void buttonPressed(int id) {
165         if (id == IDialogConstants.OK_ID) {
166             filterSyncSet();
167         }
168         super.buttonPressed(id);
169     }
170
171     protected void filterSyncSet() {
172         // Keep only the checked resources
173
if (selectedResources != null) {
174             getSyncSet().selectNodes(new FastSyncInfoFilter() {
175                 public boolean select(SyncInfo info) {
176                     IResource local = info.getLocal();
177                     for (int i = 0; i < selectedResources.length; i++) {
178                         if (local.equals(selectedResources[i])) return true;
179                     }
180                     return false;
181                 }
182             });
183         }
184     }
185 }
186
Popular Tags