|
Added
Link Here
|
| 1 |
package org.eclipse.team.internal.ccvs.ui.tags; |
| 2 |
|
| 3 |
import java.util.Arrays; |
| 4 |
import java.util.Vector; |
| 5 |
|
| 6 |
import org.eclipse.core.runtime.IStatus; |
| 7 |
import org.eclipse.jface.dialogs.IDialogConstants; |
| 8 |
import org.eclipse.jface.dialogs.IDialogSettings; |
| 9 |
import org.eclipse.jface.util.IPropertyChangeListener; |
| 10 |
import org.eclipse.jface.util.PropertyChangeEvent; |
| 11 |
import org.eclipse.swt.SWT; |
| 12 |
import org.eclipse.swt.events.*; |
| 13 |
import org.eclipse.swt.layout.GridData; |
| 14 |
import org.eclipse.swt.widgets.*; |
| 15 |
import org.eclipse.team.internal.ccvs.core.CVSTag; |
| 16 |
import org.eclipse.team.internal.ccvs.ui.CVSUIMessages; |
| 17 |
import org.eclipse.team.internal.ccvs.ui.IHelpContextIds; |
| 18 |
import org.eclipse.team.internal.ccvs.ui.operations.ITagOperation; |
| 19 |
import org.eclipse.team.internal.ccvs.ui.tags.TagSelectionArea; |
| 20 |
import org.eclipse.team.internal.ccvs.ui.tags.TagSource; |
| 21 |
import org.eclipse.team.internal.ui.*; |
| 22 |
import org.eclipse.team.internal.ui.dialogs.DetailsDialog; |
| 23 |
|
| 24 |
public class TagRemoveDialog extends DetailsDialog { |
| 25 |
|
| 26 |
private static final int TAG_AREA_HEIGHT_HINT = 200; |
| 27 |
|
| 28 |
private static final int HISTORY_LENGTH = 10; |
| 29 |
|
| 30 |
private static final String STORE_SECTION = "TagAsVersionDialog"; //$NON-NLS-1$ |
| 31 |
|
| 32 |
private static final String TAG_HISTORY = "tag_history"; //$NON-NLS-1$ |
| 33 |
|
| 34 |
private static IDialogSettings settingsSection; |
| 35 |
|
| 36 |
private ITagOperation operation; |
| 37 |
|
| 38 |
private Combo tagCombo; |
| 39 |
// private Button moveTagButton; |
| 40 |
|
| 41 |
private String tagName = ""; //$NON-NLS-1$ |
| 42 |
// private boolean moveTag = false; |
| 43 |
|
| 44 |
private TagSource tagSource; |
| 45 |
|
| 46 |
private TagSelectionArea tagArea; |
| 47 |
|
| 48 |
public TagRemoveDialog(Shell parentShell, String title, ITagOperation operation) { |
| 49 |
super(parentShell, title); |
| 50 |
this.tagSource = operation.getTagSource(); |
| 51 |
this.operation = operation; |
| 52 |
} |
| 53 |
|
| 54 |
/** |
| 55 |
* @see DetailsDialog#createMainDialogArea(Composite) |
| 56 |
*/ |
| 57 |
protected void createMainDialogArea(Composite parent) { |
| 58 |
|
| 59 |
final int width= convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH + 50); |
| 60 |
|
| 61 |
// final Label label = SWTUtils.createLabel(parent, CVSUIMessages.TagAction_enterTag); |
| 62 |
final Label label = SWTUtils.createLabel(parent, CVSUIMessages.TagRemoveDialogMessage); |
| 63 |
label.setLayoutData(SWTUtils.createGridData(width, SWT.DEFAULT, true, false)); |
| 64 |
|
| 65 |
tagCombo = createDropDownCombo(parent); |
| 66 |
tagName = ""; //$NON-NLS-1$ |
| 67 |
tagCombo.setItems(getTagNameHistory()); |
| 68 |
tagCombo.setText(tagName); |
| 69 |
tagCombo.addModifyListener( |
| 70 |
new ModifyListener() { |
| 71 |
public void modifyText(ModifyEvent e) { |
| 72 |
tagName = tagCombo.getText(); |
| 73 |
updateEnablements(); |
| 74 |
} |
| 75 |
} |
| 76 |
); |
| 77 |
|
| 78 |
// moveTagButton= SWTUtils.createCheckBox(parent, CVSUIMessages.TagAction_moveTag); |
| 79 |
// moveTagButton.addSelectionListener(new SelectionAdapter() { |
| 80 |
// public void widgetSelected(SelectionEvent e) { |
| 81 |
// moveTag = moveTagButton.getSelection(); |
| 82 |
// } |
| 83 |
// }); |
| 84 |
|
| 85 |
} |
| 86 |
|
| 87 |
/* (non-Javadoc) |
| 88 |
* @see org.eclipse.team.internal.ui.dialogs.DetailsDialog#getHelpContextId() |
| 89 |
*/ |
| 90 |
protected String getHelpContextId() { |
| 91 |
return IHelpContextIds.TAG_AS_VERSION_DIALOG; |
| 92 |
} |
| 93 |
|
| 94 |
// public boolean shouldMoveTag() { |
| 95 |
// return moveTag; |
| 96 |
// } |
| 97 |
|
| 98 |
/** |
| 99 |
* @see DetailsDialog#createDropDownDialogArea(Composite) |
| 100 |
*/ |
| 101 |
protected Composite createDropDownDialogArea(Composite parent) { |
| 102 |
|
| 103 |
final PixelConverter converter= SWTUtils.createDialogPixelConverter(parent); |
| 104 |
|
| 105 |
final Composite composite = new Composite(parent, SWT.NONE); |
| 106 |
composite.setLayout(SWTUtils.createGridLayout(1, converter, SWTUtils.MARGINS_DIALOG)); |
| 107 |
|
| 108 |
final GridData gridData = new GridData(GridData.FILL_BOTH); |
| 109 |
gridData.heightHint = TAG_AREA_HEIGHT_HINT; |
| 110 |
composite.setLayoutData(gridData); |
| 111 |
|
| 112 |
tagArea = new TagSelectionArea(getShell(), tagSource, TagSelectionArea.INCLUDE_VERSIONS, null); |
| 113 |
tagArea.setTagAreaLabel(CVSUIMessages.TagAction_existingVersions); |
| 114 |
tagArea.setIncludeFilterInputArea(false); |
| 115 |
tagArea.createArea(composite); |
| 116 |
tagArea.addPropertyChangeListener(new IPropertyChangeListener() { |
| 117 |
public void propertyChange(PropertyChangeEvent event) { |
| 118 |
if (event.getProperty().equals(TagSelectionArea.SELECTED_TAG)) { |
| 119 |
CVSTag tag = tagArea.getSelection(); |
| 120 |
if (tag != null) { |
| 121 |
tagCombo.setText(tag.getName()); |
| 122 |
} |
| 123 |
} else if (event.getProperty().equals(TagSelectionArea.OPEN_SELECTED_TAG)) { |
| 124 |
CVSTag tag = tagArea.getSelection(); |
| 125 |
if (tag != null) { |
| 126 |
tagCombo.setText(tag.getName()); |
| 127 |
okPressed(); |
| 128 |
} |
| 129 |
} |
| 130 |
} |
| 131 |
}); |
| 132 |
return composite; |
| 133 |
} |
| 134 |
|
| 135 |
/** |
| 136 |
* Validates tag name |
| 137 |
*/ |
| 138 |
protected void updateEnablements() { |
| 139 |
String message = null; |
| 140 |
if(tagName.length() == 0) { |
| 141 |
message = ""; //$NON-NLS-1$ |
| 142 |
} else { |
| 143 |
IStatus status = CVSTag.validateTagName(tagName); |
| 144 |
if (!status.isOK()) { |
| 145 |
message = status.getMessage(); |
| 146 |
} |
| 147 |
} |
| 148 |
setPageComplete(message == null); |
| 149 |
setErrorMessage(message); |
| 150 |
if (tagArea != null) { |
| 151 |
tagArea.setFilter(tagName); |
| 152 |
} |
| 153 |
} |
| 154 |
|
| 155 |
/** |
| 156 |
* Returns the tag name entered into this dialog |
| 157 |
*/ |
| 158 |
public String getTagName() { |
| 159 |
return tagName; |
| 160 |
} |
| 161 |
|
| 162 |
/** |
| 163 |
* @return |
| 164 |
*/ |
| 165 |
public ITagOperation getOperation() { |
| 166 |
operation.setTag(new CVSTag(tagName, CVSTag.VERSION)); |
| 167 |
// if (moveTag) { |
| 168 |
// operation.moveTag(); |
| 169 |
// } |
| 170 |
return operation; |
| 171 |
} |
| 172 |
|
| 173 |
/* (non-Javadoc) |
| 174 |
* @see org.eclipse.team.internal.ui.dialogs.DetailsDialog#isMainGrabVertical() |
| 175 |
*/ |
| 176 |
protected boolean isMainGrabVertical() { |
| 177 |
return false; |
| 178 |
} |
| 179 |
|
| 180 |
protected Combo createDropDownCombo(Composite parent) { |
| 181 |
Combo combo = new Combo(parent, SWT.DROP_DOWN); |
| 182 |
GridData comboData = new GridData(GridData.FILL_HORIZONTAL); |
| 183 |
comboData.verticalAlignment = GridData.CENTER; |
| 184 |
comboData.grabExcessVerticalSpace = false; |
| 185 |
comboData.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH; |
| 186 |
combo.setLayoutData(comboData); |
| 187 |
return combo; |
| 188 |
} |
| 189 |
|
| 190 |
protected void okPressed() { |
| 191 |
rememberTagName(tagName); |
| 192 |
super.okPressed(); |
| 193 |
} |
| 194 |
|
| 195 |
protected static String[] getTagNameHistory() { |
| 196 |
IDialogSettings section = getSettingsSection(); |
| 197 |
String[] array = section.getArray(TAG_HISTORY); |
| 198 |
return array != null ? array : new String[]{""}; |
| 199 |
} |
| 200 |
|
| 201 |
private void rememberTagName(String tagName) { |
| 202 |
Object[] tagNameHistory = getTagNameHistory(); |
| 203 |
Vector tagNames = new Vector(Arrays.asList(tagNameHistory)); |
| 204 |
if (tagNames.contains(tagName)) { |
| 205 |
// The item is in the list. Remove it and add it back at the |
| 206 |
// beginning. If it already was at the beginning this will be a |
| 207 |
// waste of time, but it's not even measurable. |
| 208 |
tagNames.remove(tagName); |
| 209 |
} |
| 210 |
// Most recently used filename goes to the beginning of the list |
| 211 |
tagNames.add(0, tagName); |
| 212 |
|
| 213 |
// Forget any overflowing items |
| 214 |
while (tagNames.size() > HISTORY_LENGTH) { |
| 215 |
tagNames.remove(HISTORY_LENGTH); |
| 216 |
} |
| 217 |
String[] array = (String[]) tagNames.toArray(new String[tagNames.size()]); |
| 218 |
IDialogSettings section = getSettingsSection(); |
| 219 |
section.put(TAG_HISTORY, array); |
| 220 |
} |
| 221 |
|
| 222 |
private static IDialogSettings getSettingsSection() { |
| 223 |
if (settingsSection != null) |
| 224 |
return settingsSection; |
| 225 |
|
| 226 |
IDialogSettings settings = TeamUIPlugin.getPlugin().getDialogSettings(); |
| 227 |
settingsSection = settings.getSection(STORE_SECTION); |
| 228 |
if (settingsSection != null) |
| 229 |
return settingsSection; |
| 230 |
|
| 231 |
settingsSection = settings.addNewSection(STORE_SECTION); |
| 232 |
return settingsSection; |
| 233 |
} |
| 234 |
} |