1 11 package org.eclipse.ui.internal.activities.ws; 12 13 import com.ibm.icu.text.MessageFormat; 14 import java.util.Collection ; 15 import java.util.HashSet ; 16 import java.util.Properties ; 17 import java.util.ResourceBundle ; 18 import java.util.Set ; 19 20 import org.eclipse.jface.dialogs.Dialog; 21 import org.eclipse.jface.dialogs.IDialogConstants; 22 import org.eclipse.jface.viewers.CheckStateChangedEvent; 23 import org.eclipse.jface.viewers.CheckboxTableViewer; 24 import org.eclipse.jface.viewers.ICheckStateListener; 25 import org.eclipse.jface.viewers.ISelectionChangedListener; 26 import org.eclipse.jface.viewers.IStructuredSelection; 27 import org.eclipse.jface.viewers.SelectionChangedEvent; 28 import org.eclipse.jface.window.Window; 29 import org.eclipse.swt.SWT; 30 import org.eclipse.swt.graphics.Font; 31 import org.eclipse.swt.layout.GridData; 32 import org.eclipse.swt.layout.GridLayout; 33 import org.eclipse.swt.widgets.Button; 34 import org.eclipse.swt.widgets.Composite; 35 import org.eclipse.swt.widgets.Control; 36 import org.eclipse.swt.widgets.Label; 37 import org.eclipse.swt.widgets.Shell; 38 import org.eclipse.swt.widgets.Text; 39 import org.eclipse.ui.PlatformUI; 40 import org.eclipse.ui.activities.IActivity; 41 import org.eclipse.ui.activities.IActivityManager; 42 import org.eclipse.ui.activities.NotDefinedException; 43 import org.eclipse.ui.activities.WorkbenchTriggerPointAdvisor; 44 45 51 public class EnablementDialog extends Dialog { 52 53 56 private final static ResourceBundle RESOURCE_BUNDLE = ResourceBundle 57 .getBundle(EnablementDialog.class.getName()); 58 59 private Button dontAskButton; 60 61 private Set activitiesToEnable = new HashSet (7); 62 63 private Collection activityIds; 64 65 private boolean dontAsk; 66 67 private Button detailsButton; 68 69 boolean showDetails = false; 70 71 private Composite detailsComposite; 72 73 private Label detailsLabel; 74 75 private String selectedActivity; 76 77 private Text detailsText; 78 79 private Properties strings; 80 81 88 public EnablementDialog(Shell parentShell, Collection activityIds, Properties strings) { 89 super(parentShell); 90 this.activityIds = activityIds; 91 this.strings = strings; 92 } 93 94 97 protected Control createDialogArea(Composite parent) { 98 Composite composite = (Composite) super.createDialogArea(parent); 99 Font dialogFont = parent.getFont(); 100 composite.setFont(dialogFont); 101 Label text = new Label(composite, SWT.NONE); 102 text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 103 text.setFont(dialogFont); 104 IActivityManager manager = PlatformUI.getWorkbench() 105 .getActivitySupport().getActivityManager(); 106 107 if (activityIds.size() == 1) { 108 String activityId = (String ) activityIds.iterator().next(); 109 activitiesToEnable.add(activityId); 110 selectedActivity = activityId; 111 112 IActivity activity = manager.getActivity(activityId); 113 String activityText; 114 try { 115 activityText = activity.getName(); 116 } catch (NotDefinedException e) { 117 activityText = activity.getId(); 118 } 119 text.setText(MessageFormat.format(RESOURCE_BUNDLE 120 .getString("requiresSingle"), new Object [] { activityText })); 122 123 text = new Label(composite, SWT.NONE); 124 text 125 .setText(strings 126 .getProperty( 127 WorkbenchTriggerPointAdvisor.PROCEED_SINGLE, 128 RESOURCE_BUNDLE 129 .getString(WorkbenchTriggerPointAdvisor.PROCEED_SINGLE))); 130 text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 131 text.setFont(dialogFont); 132 } else { 133 text.setText(RESOURCE_BUNDLE.getString("requiresMulti")); Set activityIdsCopy = new HashSet (activityIds); 135 CheckboxTableViewer viewer = CheckboxTableViewer.newCheckList( 136 composite, SWT.CHECK | SWT.BORDER | SWT.SINGLE); 137 viewer.setContentProvider(new ActivityContentProvider()); 138 viewer.setLabelProvider(new ActivityLabelProvider(manager)); 139 viewer.setInput(activityIdsCopy); 140 viewer.setCheckedElements(activityIdsCopy.toArray()); 141 viewer.addCheckStateListener(new ICheckStateListener() { 142 143 146 public void checkStateChanged(CheckStateChangedEvent event) { 147 if (event.getChecked()) { 148 activitiesToEnable.add(event.getElement()); 149 } else { 150 activitiesToEnable.remove(event.getElement()); 151 } 152 153 getButton(Window.OK).setEnabled( 154 !activitiesToEnable.isEmpty()); 155 } 156 }); 157 viewer.addSelectionChangedListener(new ISelectionChangedListener() { 158 161 public void selectionChanged(SelectionChangedEvent event) { 162 selectedActivity = (String ) ((IStructuredSelection) event 163 .getSelection()).getFirstElement(); 164 setDetails(); 165 } 166 }); 167 activitiesToEnable.addAll(activityIdsCopy); 168 169 viewer.getControl().setLayoutData( 170 new GridData(GridData.FILL_HORIZONTAL)); 171 viewer.getControl().setFont(dialogFont); 172 173 text = new Label(composite, SWT.NONE); 174 text.setText(strings.getProperty(WorkbenchTriggerPointAdvisor.PROCEED_MULTI, RESOURCE_BUNDLE 175 .getString(WorkbenchTriggerPointAdvisor.PROCEED_MULTI))); 176 text.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 177 text.setFont(dialogFont); 178 } 179 Label seperator = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL); 180 seperator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 181 182 dontAskButton = new Button(composite, SWT.CHECK); 183 dontAskButton.setSelection(false); 184 dontAskButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 185 dontAskButton.setText(strings.getProperty( 186 WorkbenchTriggerPointAdvisor.DONT_ASK, RESOURCE_BUNDLE 187 .getString(WorkbenchTriggerPointAdvisor.DONT_ASK))); 188 dontAskButton.setFont(dialogFont); 189 190 detailsComposite = new Composite(composite, SWT.NONE); 191 GridLayout layout = new GridLayout(); 192 layout.marginHeight = 0; 193 layout.marginWidth = 0; 194 detailsComposite.setLayout(layout); 195 detailsLabel = new Label(detailsComposite, SWT.NONE); 196 detailsLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 197 detailsLabel.setFont(dialogFont); 198 199 detailsText = new Text(detailsComposite, SWT.WRAP | SWT.V_SCROLL 200 | SWT.BORDER | SWT.READ_ONLY); 201 detailsText.setLayoutData(new GridData(GridData.FILL_BOTH)); 202 detailsText.setFont(dialogFont); 203 204 setDetails(); 205 206 GridData data = new GridData(GridData.FILL_BOTH); 207 detailsComposite.setLayoutData(data); 208 setDetailHints(); 209 210 return composite; 211 } 212 213 216 protected void setDetails() { 217 if (selectedActivity == null) { 218 detailsLabel 219 .setText(strings 220 .getProperty( 221 WorkbenchTriggerPointAdvisor.NO_DETAILS, 222 RESOURCE_BUNDLE 223 .getString(WorkbenchTriggerPointAdvisor.NO_DETAILS))); 224 detailsText.setText(""); } else { 226 IActivity activity = PlatformUI.getWorkbench().getActivitySupport() 227 .getActivityManager().getActivity(selectedActivity); 228 String name; 229 try { 230 name = activity.getName(); 231 } catch (NotDefinedException e1) { 232 name = selectedActivity; 233 } 234 String desc; 235 try { 236 desc = activity.getDescription(); 237 } catch (NotDefinedException e) { 238 desc = RESOURCE_BUNDLE.getString("noDescAvailable"); } 240 detailsLabel.setText(MessageFormat.format(RESOURCE_BUNDLE 241 .getString("detailsLabel"), new Object [] { name })); detailsText.setText(desc); 243 } 244 } 245 246 249 protected void setDetailHints() { 250 GridData data = (GridData) detailsComposite.getLayoutData(); 251 if (showDetails) { 252 Composite parent = detailsComposite.getParent(); 253 data.widthHint = parent.getSize().x - ((GridLayout)parent.getLayout()).marginWidth * 2; 254 data.heightHint = convertHeightInCharsToPixels(5); 255 } else { 256 data.widthHint = 0; 257 data.heightHint = 0; 258 } 259 } 260 261 264 private void setDetailButtonLabel() { 265 if (!showDetails) { 266 detailsButton.setText(RESOURCE_BUNDLE.getString("showDetails")); } else { 268 detailsButton.setText(RESOURCE_BUNDLE.getString("hideDetails")); } 270 } 271 272 275 protected void configureShell(Shell newShell) { 276 super.configureShell(newShell); 277 newShell.setText(RESOURCE_BUNDLE.getString("title")); } 279 280 284 public boolean getDontAsk() { 285 return dontAsk; 286 } 287 288 291 public Set getActivitiesToEnable() { 292 return activitiesToEnable; 293 } 294 295 298 protected void okPressed() { 299 dontAsk = dontAskButton.getSelection(); 300 super.okPressed(); 301 } 302 303 306 protected void createButtonsForButtonBar(Composite parent) { 307 super.createButtonsForButtonBar(parent); 308 detailsButton = createButton(parent, IDialogConstants.DETAILS_ID, 309 "", false); setDetailButtonLabel(); 311 } 312 313 316 protected void buttonPressed(int buttonId) { 317 if (buttonId == IDialogConstants.DETAILS_ID) { 318 detailsPressed(); 319 return; 320 } 321 super.buttonPressed(buttonId); 322 } 323 324 327 private void detailsPressed() { 328 showDetails = !showDetails; 329 setDetailButtonLabel(); 330 setDetailHints(); 331 setDetails(); 332 ((Composite) getDialogArea()).layout(true); 333 getShell().setSize(getShell().computeSize(SWT.DEFAULT, SWT.DEFAULT)); 334 } 335 } 336 | Popular Tags |