KickJava   Java API By Example, From Geeks To Geeks.

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


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.tags;
12
13 import org.eclipse.core.runtime.IStatus;
14 import org.eclipse.jface.dialogs.IDialogConstants;
15 import org.eclipse.jface.util.IPropertyChangeListener;
16 import org.eclipse.jface.util.PropertyChangeEvent;
17 import org.eclipse.swt.SWT;
18 import org.eclipse.swt.events.*;
19 import org.eclipse.swt.layout.GridData;
20 import org.eclipse.swt.widgets.*;
21 import org.eclipse.team.internal.ccvs.core.CVSTag;
22 import org.eclipse.team.internal.ccvs.ui.CVSUIMessages;
23 import org.eclipse.team.internal.ccvs.ui.IHelpContextIds;
24 import org.eclipse.team.internal.ccvs.ui.operations.ITagOperation;
25 import org.eclipse.team.internal.ui.PixelConverter;
26 import org.eclipse.team.internal.ui.SWTUtils;
27 import org.eclipse.team.internal.ui.dialogs.DetailsDialog;
28
29 public class TagAsVersionDialog extends DetailsDialog {
30
31     private static final int TAG_AREA_HEIGHT_HINT = 200;
32     
33     private ITagOperation operation;
34     
35     private Text tagText;
36     private Button moveTagButton;
37     
38     private String JavaDoc tagName = ""; //$NON-NLS-1$
39
private boolean moveTag = false;
40
41     private TagSource tagSource;
42
43     private TagSelectionArea tagArea;
44     
45     public TagAsVersionDialog(Shell parentShell, String JavaDoc title, ITagOperation operation) {
46         super(parentShell, title);
47         this.tagSource = operation.getTagSource();
48         this.operation = operation;
49     }
50     
51     /**
52      * @see DetailsDialog#createMainDialogArea(Composite)
53      */

54     protected void createMainDialogArea(Composite parent) {
55         
56         final int width= convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH + 50);
57         
58         final Label label = SWTUtils.createLabel(parent, CVSUIMessages.TagAction_enterTag);
59         label.setLayoutData(SWTUtils.createGridData(width, SWT.DEFAULT, true, false));
60
61         tagText = new Text(parent, SWT.SINGLE | SWT.BORDER);
62         tagText.setLayoutData(SWTUtils.createHFillGridData());
63         tagText.addModifyListener(
64             new ModifyListener() {
65                 public void modifyText(ModifyEvent e) {
66                     tagName = tagText.getText();
67                     updateEnablements();
68                 }
69             }
70         );
71         
72         moveTagButton= SWTUtils.createCheckBox(parent, CVSUIMessages.TagAction_moveTag);
73         moveTagButton.addSelectionListener(new SelectionAdapter() {
74             public void widgetSelected(SelectionEvent e) {
75                 moveTag = moveTagButton.getSelection();
76             }
77         });
78
79     }
80
81     /* (non-Javadoc)
82      * @see org.eclipse.team.internal.ui.dialogs.DetailsDialog#getHelpContextId()
83      */

84     protected String JavaDoc getHelpContextId() {
85         return IHelpContextIds.TAG_AS_VERSION_DIALOG;
86     }
87
88     public boolean shouldMoveTag() {
89         return moveTag;
90     }
91     
92     /**
93      * @see DetailsDialog#createDropDownDialogArea(Composite)
94      */

95     protected Composite createDropDownDialogArea(Composite parent) {
96         
97         final PixelConverter converter= SWTUtils.createDialogPixelConverter(parent);
98         
99         final Composite composite = new Composite(parent, SWT.NONE);
100         composite.setLayout(SWTUtils.createGridLayout(1, converter, SWTUtils.MARGINS_DIALOG));
101         
102         final GridData gridData = new GridData(GridData.FILL_BOTH);
103         gridData.heightHint = TAG_AREA_HEIGHT_HINT;
104         composite.setLayoutData(gridData);
105         
106         tagArea = new TagSelectionArea(getShell(), tagSource, TagSelectionArea.INCLUDE_VERSIONS, null);
107         tagArea.setTagAreaLabel(CVSUIMessages.TagAction_existingVersions);
108         tagArea.setIncludeFilterInputArea(false);
109         tagArea.createArea(composite);
110         tagArea.addPropertyChangeListener(new IPropertyChangeListener() {
111             public void propertyChange(PropertyChangeEvent event) {
112                 if (event.getProperty().equals(TagSelectionArea.SELECTED_TAG)) {
113                     CVSTag tag = tagArea.getSelection();
114                     if (tag != null) {
115                         tagText.setText(tag.getName());
116                     }
117                 } else if (event.getProperty().equals(TagSelectionArea.OPEN_SELECTED_TAG)) {
118                     CVSTag tag = tagArea.getSelection();
119                     if (tag != null) {
120                         tagText.setText(tag.getName());
121                         okPressed();
122                     }
123                 }
124             }
125         });
126         return composite;
127     }
128     
129     /**
130      * Validates tag name
131      */

132     protected void updateEnablements() {
133         String JavaDoc message = null;
134         if(tagName.length() == 0) {
135             message = ""; //$NON-NLS-1$
136
} else {
137             IStatus status = CVSTag.validateTagName(tagName);
138             if (!status.isOK()) {
139                 message = status.getMessage();
140             }
141         }
142         setPageComplete(message == null);
143         setErrorMessage(message);
144         if (tagArea != null) {
145             tagArea.setFilter(tagName);
146         }
147     }
148     
149     /**
150      * Returns the tag name entered into this dialog
151      */

152     public String JavaDoc getTagName() {
153         return tagName;
154     }
155     
156     /**
157      * @return
158      */

159     public ITagOperation getOperation() {
160         operation.setTag(new CVSTag(tagName, CVSTag.VERSION));
161         if (moveTag) {
162             operation.moveTag();
163         }
164         return operation;
165     }
166     
167     /* (non-Javadoc)
168      * @see org.eclipse.team.internal.ui.dialogs.DetailsDialog#isMainGrabVertical()
169      */

170     protected boolean isMainGrabVertical() {
171         return false;
172     }
173
174 }
175
Popular Tags