KickJava   Java API By Example, From Geeks To Geeks.

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


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

11 package org.eclipse.team.internal.ccvs.ui;
12
13 import org.eclipse.core.runtime.IStatus;
14 import org.eclipse.jface.dialogs.Dialog;
15 import org.eclipse.jface.dialogs.IDialogConstants;
16 import org.eclipse.jface.viewers.ColumnWeightData;
17 import org.eclipse.jface.viewers.ISelectionChangedListener;
18 import org.eclipse.jface.viewers.IStructuredSelection;
19 import org.eclipse.jface.viewers.SelectionChangedEvent;
20 import org.eclipse.jface.viewers.TableLayout;
21 import org.eclipse.jface.viewers.TableViewer;
22 import org.eclipse.jface.viewers.Viewer;
23 import org.eclipse.jface.viewers.ViewerSorter;
24 import org.eclipse.swt.SWT;
25 import org.eclipse.swt.events.ModifyEvent;
26 import org.eclipse.swt.events.ModifyListener;
27 import org.eclipse.swt.events.SelectionAdapter;
28 import org.eclipse.swt.events.SelectionEvent;
29 import org.eclipse.swt.layout.GridData;
30 import org.eclipse.swt.layout.GridLayout;
31 import org.eclipse.swt.widgets.Button;
32 import org.eclipse.swt.widgets.Composite;
33 import org.eclipse.swt.widgets.Label;
34 import org.eclipse.swt.widgets.Shell;
35 import org.eclipse.swt.widgets.Table;
36 import org.eclipse.swt.widgets.TableColumn;
37 import org.eclipse.swt.widgets.Text;
38 import org.eclipse.team.internal.ccvs.core.CVSTag;
39 import org.eclipse.team.internal.ccvs.core.ICVSFolder;
40 import org.eclipse.team.internal.ccvs.core.ICVSResource;
41 import org.eclipse.team.internal.ccvs.ui.merge.TagElement;
42 import org.eclipse.team.internal.ccvs.ui.merge.TagRootElement;
43 import org.eclipse.team.internal.ccvs.ui.operations.ITagOperation;
44 import org.eclipse.team.internal.ui.dialogs.DetailsDialog;
45 import org.eclipse.ui.help.WorkbenchHelp;
46 import org.eclipse.ui.model.WorkbenchContentProvider;
47 import org.eclipse.ui.model.WorkbenchLabelProvider;
48
49 public class TagAsVersionDialog extends DetailsDialog {
50
51     private ITagOperation operation;
52
53     private ICVSFolder folder;
54     
55     private Text tagText;
56     private Button moveTagButton;
57     
58     private String JavaDoc tagName = ""; //$NON-NLS-1$
59
private boolean moveTag = false;
60     
61     private static final int TABLE_HEIGHT_HINT = 150;
62     
63     private TableViewer existingVersionTable;
64     
65     public TagAsVersionDialog(Shell parentShell, String JavaDoc title, ITagOperation operation) {
66         super(parentShell, title);
67         this.folder = getFirstFolder(operation.getCVSResources());
68         this.operation = operation;
69     }
70
71     private ICVSFolder getFirstFolder(ICVSResource[] resources) {
72         if (resources[0].isFolder()) {
73             return (ICVSFolder)resources[0];
74         } else {
75             return resources[0].getParent();
76         }
77     }
78     
79     /**
80      * @see DetailsDialog#createMainDialogArea(Composite)
81      */

82     protected void createMainDialogArea(Composite parent) {
83         // create message
84
Label label = new Label(parent, SWT.WRAP);
85         label.setText(Policy.bind("TagAction.enterTag")); //$NON-NLS-1$
86
GridData data = new GridData(
87             GridData.GRAB_HORIZONTAL |
88             GridData.GRAB_VERTICAL |
89             GridData.HORIZONTAL_ALIGN_FILL |
90             GridData.VERTICAL_ALIGN_CENTER);
91         data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);;
92         label.setLayoutData(data);
93
94         tagText = new Text(parent, SWT.SINGLE | SWT.BORDER);
95         tagText.setLayoutData(new GridData(
96             GridData.GRAB_HORIZONTAL |
97             GridData.HORIZONTAL_ALIGN_FILL));
98         tagText.addModifyListener(
99             new ModifyListener() {
100                 public void modifyText(ModifyEvent e) {
101                     tagName = tagText.getText();
102                     updateEnablements();
103                 }
104             }
105         );
106         
107         moveTagButton = new Button(parent, SWT.CHECK);
108         moveTagButton.setText(Policy.bind("TagAction.moveTag")); //$NON-NLS-1$
109
moveTagButton.setLayoutData(new GridData(
110             GridData.GRAB_HORIZONTAL |
111             GridData.GRAB_VERTICAL |
112             GridData.HORIZONTAL_ALIGN_FILL |
113             GridData.VERTICAL_ALIGN_CENTER));
114         
115         moveTagButton.addSelectionListener(new SelectionAdapter() {
116             public void widgetSelected(SelectionEvent e) {
117                 moveTag = moveTagButton.getSelection();
118             }
119         });
120         
121         // Add F1 help
122
WorkbenchHelp.setHelp(parent, IHelpContextIds.TAG_AS_VERSION_DIALOG);
123         Dialog.applyDialogFont(parent);
124     }
125
126     public boolean shouldMoveTag() {
127         return moveTag;
128     }
129     
130     protected TableViewer createTable(Composite parent) {
131         Table table = new Table(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.SINGLE | SWT.FULL_SELECTION);
132         GridData data = new GridData(GridData.FILL_BOTH);
133         data.heightHint = TABLE_HEIGHT_HINT;
134         table.setLayoutData(data);
135         TableLayout layout = new TableLayout();
136         layout.addColumnData(new ColumnWeightData(100, true));
137         table.setLayout(layout);
138         TableColumn col = new TableColumn(table, SWT.NONE);
139         col.setResizable(true);
140         return new TableViewer(table);
141     }
142     
143     /**
144      * @see DetailsDialog#createDropDownDialogArea(Composite)
145      */

146     protected Composite createDropDownDialogArea(Composite parent) {
147         // create a composite with standard margins and spacing
148
Composite composite = new Composite(parent, SWT.NONE);
149         GridLayout layout = new GridLayout();
150         layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
151         layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
152         layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
153         layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
154         composite.setLayout(layout);
155         composite.setLayoutData(new GridData(GridData.FILL_BOTH));
156         
157         Label label = new Label(composite, SWT.WRAP);
158         label.setText(Policy.bind("TagAction.existingVersions")); //$NON-NLS-1$
159
GridData data = new GridData(
160             GridData.GRAB_HORIZONTAL |
161             GridData.GRAB_VERTICAL |
162             GridData.HORIZONTAL_ALIGN_FILL |
163             GridData.VERTICAL_ALIGN_CENTER);
164         data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);;
165         label.setLayoutData(data);
166         
167         existingVersionTable = createTable(composite);
168         existingVersionTable.setContentProvider(new WorkbenchContentProvider());
169         existingVersionTable.setLabelProvider(new WorkbenchLabelProvider());
170         existingVersionTable.setSorter(new ViewerSorter() {
171             public int compare(Viewer v, Object JavaDoc o1, Object JavaDoc o2) {
172                 int result = super.compare(v, o1, o2);
173                 if (o1 instanceof TagElement && o2 instanceof TagElement) {
174                     return -result;
175                 }
176                 return result;
177             }
178         });
179         existingVersionTable.addSelectionChangedListener(new ISelectionChangedListener() {
180             public void selectionChanged(SelectionChangedEvent event) {
181                 IStructuredSelection selection = (IStructuredSelection)existingVersionTable.getSelection();
182                 if(!selection.isEmpty()) {
183                     TagElement element = (TagElement)((IStructuredSelection)existingVersionTable.getSelection()).getFirstElement();
184                     if(element!=null) {
185                         tagText.setText(element.getTag().getName());
186                     }
187                 }
188             }
189         });
190
191         Runnable JavaDoc afterRefresh = new Runnable JavaDoc() {
192             public void run() {
193                 getShell().getDisplay().syncExec(new Runnable JavaDoc() {
194                     public void run() {
195                         existingVersionTable.refresh();
196                     }
197                 });
198             }
199         };
200         
201         Runnable JavaDoc afterConfigure = new Runnable JavaDoc() {
202             public void run() {
203                 getShell().getDisplay().syncExec(new Runnable JavaDoc() {
204                     public void run() {
205                         existingVersionTable.setInput(new TagRootElement(folder, CVSTag.VERSION));
206                     }
207                 });
208             }
209         };
210         
211         TagConfigurationDialog.createTagDefinitionButtons(getShell(), composite, new ICVSFolder[] {folder},
212                                                           convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT),
213                                                           convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH),
214                                                           afterRefresh, afterConfigure);
215         
216         existingVersionTable.setInput(new TagRootElement(folder, CVSTag.VERSION));
217         Dialog.applyDialogFont(parent);
218         return composite;
219     }
220     
221     /**
222      * Validates tag name
223      */

224     protected void updateEnablements() {
225         String JavaDoc message = null;
226         boolean exists = false;
227         if(tagName.length() == 0) {
228             message = ""; //$NON-NLS-1$
229
} else {
230             IStatus status = CVSTag.validateTagName(tagName);
231             if (!status.isOK()) {
232                 message = status.getMessage();
233             }
234         }
235         setPageComplete(message == null);
236         setErrorMessage(message);
237     }
238     
239     /**
240      * Returns the tag name entered into this dialog
241      */

242     public String JavaDoc getTagName() {
243         return tagName;
244     }
245     
246     /**
247      * @return
248      */

249     public ITagOperation getOperation() {
250         operation.setTag(new CVSTag(tagName, CVSTag.VERSION));
251         if (moveTag) {
252             operation.moveTag();
253         }
254         return operation;
255     }
256
257 }
258
Popular Tags