1 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.ISelectionChangedListener; 17 import org.eclipse.jface.viewers.SelectionChangedEvent; 18 import org.eclipse.jface.viewers.TreeViewer; 19 import org.eclipse.swt.SWT; 20 import org.eclipse.swt.layout.GridData; 21 import org.eclipse.swt.layout.GridLayout; 22 import org.eclipse.swt.widgets.Button; 23 import org.eclipse.swt.widgets.Composite; 24 import org.eclipse.swt.widgets.Event; 25 import org.eclipse.swt.widgets.Label; 26 import org.eclipse.swt.widgets.Listener; 27 import org.eclipse.swt.widgets.Shell; 28 import org.eclipse.swt.widgets.Text; 29 import org.eclipse.swt.widgets.Tree; 30 import org.eclipse.team.internal.ccvs.core.CVSTag; 31 import org.eclipse.team.internal.ccvs.core.ICVSFolder; 32 import org.eclipse.team.internal.ccvs.ui.merge.ProjectElement; 33 import org.eclipse.team.internal.ccvs.ui.repo.RepositorySorter; 34 import org.eclipse.team.internal.ccvs.ui.wizards.CVSWizardPage; 35 import org.eclipse.team.internal.ui.dialogs.DetailsDialog; 36 import org.eclipse.ui.help.WorkbenchHelp; 37 import org.eclipse.ui.model.WorkbenchContentProvider; 38 import org.eclipse.ui.model.WorkbenchLabelProvider; 39 40 public class BranchPromptDialog extends DetailsDialog { 41 42 private ICVSFolder folder; 43 private String branchTag = ""; private String versionTag= ""; private String versionName= ""; 47 private boolean allStickyResources; 48 private boolean update; 49 50 private Text versionText; 51 private Text branchText; 52 53 private static final int TABLE_HEIGHT_HINT = 150; 54 55 private TreeViewer tagTree; 57 58 public BranchPromptDialog(Shell parentShell, String title, ICVSFolder folder, boolean allResourcesSticky, String versionName) { 59 super(parentShell, title); 60 this.folder = folder; 61 this.allStickyResources = allResourcesSticky; 62 this.versionName = versionName; 63 } 64 65 68 protected void createMainDialogArea(Composite composite) { 69 Label label = new Label(composite, SWT.WRAP); 71 String message; 72 if(allStickyResources) { 73 message = Policy.bind("BranchWizardPage.pageDescriptionVersion"); } else { 75 message = Policy.bind("BranchWizardPage.pageDescription"); } 77 label.setText(message); 78 GridData data = new GridData( 79 GridData.GRAB_HORIZONTAL | 80 GridData.GRAB_VERTICAL | 81 GridData.HORIZONTAL_ALIGN_FILL | 82 GridData.VERTICAL_ALIGN_CENTER); 83 data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);; 84 label.setLayoutData(data); 85 86 CVSWizardPage.createLabel(composite, Policy.bind("BranchWizardPage.branchName")); branchText = CVSWizardPage.createTextField(composite); 88 branchText.addListener(SWT.Modify, new Listener() { 89 public void handleEvent(Event event) { 90 branchTag = branchText.getText(); 91 updateEnablements(); 92 updateVersionName(branchTag); 93 } 94 }); 95 96 final Button check = new Button(composite, SWT.CHECK); 97 data = new GridData(); 98 data.horizontalSpan = 2; 99 check.setLayoutData(data); 100 check.setText(Policy.bind("BranchWizardPage.startWorking")); check.addListener(SWT.Selection, new Listener() { 102 public void handleEvent(Event event) { 103 update = check.getSelection(); 104 } 105 }); 106 check.setSelection(true); 107 update = true; 108 109 label = new Label(composite, SWT.WRAP); 110 label.setText(Policy.bind("BranchWizardPage.specifyVersion")); data = new GridData(); 112 data.horizontalSpan = 2; 113 data.widthHint = 350; 114 label.setLayoutData(data); 115 116 CVSWizardPage.createLabel(composite, Policy.bind("BranchWizardPage.versionName")); versionText = CVSWizardPage.createTextField(composite); 118 versionText.addListener(SWT.Modify, new Listener() { 119 public void handleEvent(Event event) { 120 versionTag = versionText.getText(); 121 updateEnablements(); 122 } 123 }); 124 125 if(allStickyResources) { 126 versionText.setEditable(false); 127 versionText.setText(versionName); 128 } 129 130 WorkbenchHelp.setHelp(composite, IHelpContextIds.BRANCH_DIALOG); 132 Dialog.applyDialogFont(composite); 133 branchText.setFocus(); 134 } 135 136 139 protected void updateVersionName(String branchName) { 140 if(versionText!=null && !allStickyResources) { 141 versionText.setText(Policy.bind("BranchWizardPage.versionPrefix") + branchName); } 143 } 144 145 148 protected Composite createDropDownDialogArea(Composite parent) { 149 150 Composite composite = new Composite(parent, SWT.NONE); 152 GridLayout layout = new GridLayout(); 153 layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); 154 layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); 155 layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); 156 layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); 157 composite.setLayout(layout); 158 composite.setLayoutData(new GridData(GridData.FILL_BOTH)); 159 160 Label label = new Label(composite, SWT.WRAP); 161 label.setText(Policy.bind("BranchWizardPage.existingVersionsAndBranches")); GridData data = new GridData( 163 GridData.GRAB_HORIZONTAL | 164 GridData.GRAB_VERTICAL | 165 GridData.HORIZONTAL_ALIGN_FILL | 166 GridData.VERTICAL_ALIGN_CENTER); 167 data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);; 168 label.setLayoutData(data); 169 170 tagTree = createTree(composite); 171 tagTree.setInput(new ProjectElement(folder, ProjectElement.INCLUDE_BRANCHES | ProjectElement.INCLUDE_VERSIONS)); 172 Runnable refresh = new Runnable () { 173 public void run() { 174 getShell().getDisplay().syncExec(new Runnable () { 175 public void run() { 176 tagTree.refresh(); 177 } 178 }); 179 } 180 }; 181 TagConfigurationDialog.createTagDefinitionButtons(getShell(), composite, new ICVSFolder[] {folder}, 182 convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT), 183 convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH), 184 refresh, refresh); 185 Dialog.applyDialogFont(parent); 186 return composite; 187 } 188 189 192 protected TreeViewer createTree(Composite parent) { 193 Tree tree = new Tree(parent, SWT.SINGLE | SWT.BORDER); 194 GridData data = new GridData(GridData.FILL_BOTH); 195 data.heightHint = TABLE_HEIGHT_HINT; 196 tree.setLayoutData(data); 197 TreeViewer result = new TreeViewer(tree); 198 result.setContentProvider(new WorkbenchContentProvider()); 199 result.setLabelProvider(new WorkbenchLabelProvider()); 200 result.addSelectionChangedListener(new ISelectionChangedListener() { 201 public void selectionChanged(SelectionChangedEvent event) { 202 } 203 }); 204 result.setSorter(new RepositorySorter()); 205 return result; 206 } 207 208 211 protected void updateEnablements() { 212 String message = null; 213 boolean complete = false; 214 215 if (branchTag.length() == 0) { 216 message = ""; } else { 218 IStatus status = CVSTag.validateTagName(branchTag); 219 if (!status.isOK()) { 220 message = Policy.bind("BranchWizard.branchNameWarning", status.getMessage()); } else { 222 if(versionText!=null) { 223 status = CVSTag.validateTagName(versionText.getText()); 224 if (!status.isOK()) { 225 message = Policy.bind("BranchWizard.versionNameWarning", status.getMessage()); } else { 227 if(versionTag.length() != 0 && versionTag.equals(branchTag)) { 228 message = Policy.bind("BranchWizard.branchAndVersionMustBeDifferent"); } 230 } 231 } 232 } 233 } 234 setPageComplete(message == null); 235 setErrorMessage(message); 236 } 237 238 241 public String getBranchTagName() { 242 return branchTag; 243 } 244 245 248 public String getVersionTagName() { 249 return versionTag; 250 } 251 252 255 public boolean getUpdate() { 256 return update; 257 } 258 } 259 | Popular Tags |