1 11 package org.eclipse.team.internal.ui.dialogs; 12 13 import org.eclipse.core.resources.mapping.ResourceMapping; 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.layout.GridData; 19 import org.eclipse.swt.widgets.*; 20 21 25 public abstract class MappingSelectionDialog extends DetailsDialog implements IPropertyChangeListener { 26 27 private final ResourceMapping[] mappings; 28 private ResourceMapping[] checkedMappings; 29 private ResourceMappingSelectionArea mappingArea; 30 private ResourceMappingResourceDisplayArea resourceArea; 31 private final IResourceMappingResourceFilter filter; 32 33 protected MappingSelectionDialog(Shell parentShell, String dialogTitle, ResourceMapping[] mappings, IResourceMappingResourceFilter filter) { 34 super(parentShell, dialogTitle); 35 this.mappings = mappings; 36 this.filter = filter; 37 } 38 39 42 protected void createMainDialogArea(Composite parent) { 43 if (mappings.length == 1) { 44 createWrappingLabel(parent, getSingleMappingMessage(mappings[0])); 46 } else { 47 createMappingSelectionArea(parent); 49 } 50 } 51 52 55 private void createMappingSelectionArea(Composite parent) { 56 Composite composite = createComposite(parent); 57 mappingArea = new ResourceMappingSelectionArea(mappings, true, true); 58 mappingArea.setDescription(getMultipleMappingsMessage()); 59 mappingArea.addPropertyChangeListener(this); 60 mappingArea.createArea(composite); 61 Label seperator = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL); 63 seperator.setLayoutData(new GridData (GridData.FILL_HORIZONTAL)); 64 65 checkedMappings = mappingArea.getCheckedMappings(); 66 } 67 68 71 protected Composite createDropDownDialogArea(Composite parent) { 72 if (resourceArea == null) { 73 ResourceMapping selectedMapping = getSelectedMapping(); 74 resourceArea = new ResourceMappingResourceDisplayArea(selectedMapping, getResourceListMessage(selectedMapping), filter); 75 } 76 Composite c = createComposite(parent); 77 resourceArea.createArea(c); 78 return c; 79 } 80 81 private ResourceMapping getSelectedMapping() { 82 if (mappingArea != null) 83 return mappingArea.getSelectedMapping(); 84 if (mappings.length == 1) 85 return mappings[0]; 86 return null; 87 } 88 89 92 protected void updateEnablements() { 93 setPageComplete(true); 95 } 96 97 100 protected boolean includeErrorMessage() { 101 return false; 102 } 103 104 107 protected boolean includeOkButton() { 108 return mappings.length != 1; 109 } 110 111 114 protected void createButtonsForButtonBar(Composite parent) { 115 if (mappings.length == 1) { 116 createButton(parent, IDialogConstants.YES_ID, IDialogConstants.YES_LABEL, true); 117 createButton(parent, IDialogConstants.NO_ID, IDialogConstants.NO_LABEL, false); 118 } 119 super.createButtonsForButtonBar(parent); 120 } 121 122 125 protected void buttonPressed(int id) { 126 if (IDialogConstants.YES_ID == id) { 127 checkedMappings = mappings; 128 super.buttonPressed(IDialogConstants.OK_ID); 129 } else if (IDialogConstants.NO_ID == id) { 130 checkedMappings = new ResourceMapping[0]; 131 super.buttonPressed(IDialogConstants.OK_ID); 132 } else { 133 super.buttonPressed(id); 134 } 135 } 136 137 140 public void propertyChange(PropertyChangeEvent event) { 141 if (event.getProperty().equals(ResourceMappingSelectionArea.SELECTED_MAPPING)) { 142 if (resourceArea != null) { 143 ResourceMapping selectedMapping = getSelectedMapping(); 144 resourceArea.setMapping(selectedMapping, getResourceListMessage(selectedMapping)); 145 } 146 } else if (event.getProperty().equals(ResourceMappingSelectionArea.CHECKED_MAPPINGS)) { 147 checkedMappings = mappingArea.getCheckedMappings(); 148 updateEnablements(); 149 } 150 } 151 152 157 protected abstract String getSingleMappingMessage(ResourceMapping mapping); 158 159 163 protected abstract String getMultipleMappingsMessage(); 164 165 171 protected abstract String getResourceListMessage(ResourceMapping mapping); 172 173 179 public final ResourceMapping[] getMappings() { 180 return mappings; 181 } 182 183 188 protected final ResourceMapping[] getCheckedMappings() { 189 return checkedMappings; 190 } 191 } 192 | Popular Tags |