1 12 13 package org.eclipse.jdt.internal.ui.wizards.buildpaths.newsourcepage; 14 15 import java.util.ArrayList ; 16 import java.util.List ; 17 18 import org.eclipse.swt.SWT; 19 import org.eclipse.swt.widgets.ToolBar; 20 21 import org.eclipse.jface.action.IMenuManager; 22 import org.eclipse.jface.action.Separator; 23 import org.eclipse.jface.action.ToolBarManager; 24 import org.eclipse.jface.operation.IRunnableContext; 25 import org.eclipse.jface.viewers.IStructuredSelection; 26 27 import org.eclipse.ui.PlatformUI; 28 29 import org.eclipse.jdt.internal.corext.buildpath.IBuildpathModifierListener; 30 31 import org.eclipse.jdt.internal.ui.actions.CompositeActionGroup; 32 import org.eclipse.jdt.internal.ui.util.ViewerPane; 33 34 38 public class DialogPackageExplorerActionGroup extends CompositeActionGroup { 39 40 private DialogPackageExplorer fDialogPackageExplorer; 41 42 private final AddFolderToBuildpathAction fAddFolderToBuildpathAction; 43 private final RemoveFromBuildpathAction fRemoveFromBuildpathAction; 44 private final ExcludeFromBuildpathAction fExcludeFromBuildpathAction; 45 private final IncludeToBuildpathAction fIncludeToBuildpathAction; 46 private final EditFilterAction fEditFilterAction; 47 private final EditOutputFolderAction fEditOutputFolderAction; 48 private final ClasspathModifierDropDownAction fDropDownAction; 49 private final CreateLinkedSourceFolderAction fCreateLinkedSourceFolderAction; 50 private final CreateSourceFolderAction fCreateSourceFolderAction; 51 private final ResetAllAction fResetAllAction; 52 53 63 public DialogPackageExplorerActionGroup(HintTextGroup provider, IRunnableContext context, DialogPackageExplorer dialogPackageExplorer, final NewSourceContainerWorkbookPage page) { 64 super(); 65 66 fDialogPackageExplorer= dialogPackageExplorer; 67 68 if (context == null) 69 context= PlatformUI.getWorkbench().getProgressService(); 70 71 fAddFolderToBuildpathAction= new AddFolderToBuildpathAction(context, fDialogPackageExplorer) { 72 public void run() { 73 page.commitDefaultOutputFolder(); 74 super.run(); 75 } 76 }; 77 fDialogPackageExplorer.addSelectionChangedListener(fAddFolderToBuildpathAction); 78 79 fRemoveFromBuildpathAction= new RemoveFromBuildpathAction(context, fDialogPackageExplorer) { 80 public void run() { 81 page.commitDefaultOutputFolder(); 82 super.run(); 83 } 84 }; 85 fDialogPackageExplorer.addSelectionChangedListener(fRemoveFromBuildpathAction); 86 87 fExcludeFromBuildpathAction= new ExcludeFromBuildpathAction(context, fDialogPackageExplorer) { 88 public void run() { 89 page.commitDefaultOutputFolder(); 90 super.run(); 91 } 92 }; 93 fDialogPackageExplorer.addSelectionChangedListener(fExcludeFromBuildpathAction); 94 95 fIncludeToBuildpathAction= new IncludeToBuildpathAction(context, fDialogPackageExplorer) { 96 public void run() { 97 page.commitDefaultOutputFolder(); 98 super.run(); 99 } 100 }; 101 fDialogPackageExplorer.addSelectionChangedListener(fIncludeToBuildpathAction); 102 103 fEditFilterAction= new EditFilterAction(context, fDialogPackageExplorer) { 104 public void run() { 105 page.commitDefaultOutputFolder(); 106 super.run(); 107 } 108 }; 109 fDialogPackageExplorer.addSelectionChangedListener(fEditFilterAction); 110 111 fEditOutputFolderAction= new EditOutputFolderAction(context, fDialogPackageExplorer) { 112 public void run() { 113 page.commitDefaultOutputFolder(); 114 super.run(); 115 } 116 }; 117 fDialogPackageExplorer.addSelectionChangedListener(fEditOutputFolderAction); 118 119 fDropDownAction= new ClasspathModifierDropDownAction(); 120 fDropDownAction.addAction(fEditFilterAction); 121 fDropDownAction.addAction(fEditOutputFolderAction); 122 fDialogPackageExplorer.addPostSelectionChangedListener(fDropDownAction); 123 124 fCreateLinkedSourceFolderAction= new CreateLinkedSourceFolderAction2(provider, context, fDialogPackageExplorer) { 125 public void run() { 126 page.commitDefaultOutputFolder(); 127 super.run(); 128 } 129 130 133 protected List getSelectedElements() { 134 ArrayList result= new ArrayList (); 135 result.add(page.getJavaProject()); 136 return result; 137 } 138 139 142 protected boolean canHandle(IStructuredSelection selection) { 143 return true; 144 } 145 }; 146 147 fCreateSourceFolderAction= new CreateSourceFolderAction2(provider, context, fDialogPackageExplorer) { 148 public void run() { 149 page.commitDefaultOutputFolder(); 150 super.run(); 151 } 152 153 156 protected List getSelectedElements() { 157 ArrayList result= new ArrayList (); 158 result.add(page.getJavaProject()); 159 return result; 160 } 161 162 165 protected boolean canHandle(IStructuredSelection selection) { 166 return true; 167 } 168 }; 169 170 fResetAllAction= new ResetAllAction(provider, context, fDialogPackageExplorer); 171 172 173 } 180 181 184 public void dispose() { 185 super.dispose(); 186 187 fDialogPackageExplorer.removeSelectionChangedListener(fAddFolderToBuildpathAction); 188 fDialogPackageExplorer.removeSelectionChangedListener(fRemoveFromBuildpathAction); 189 fDialogPackageExplorer.removeSelectionChangedListener(fExcludeFromBuildpathAction); 190 fDialogPackageExplorer.removeSelectionChangedListener(fIncludeToBuildpathAction); 191 fDialogPackageExplorer.removeSelectionChangedListener(fEditFilterAction); 192 fDialogPackageExplorer.removeSelectionChangedListener(fEditOutputFolderAction); 193 fDialogPackageExplorer.removePostSelectionChangedListener(fDropDownAction); 194 fDialogPackageExplorer= null; 195 } 196 197 public void addBuildpathModifierListener(IBuildpathModifierListener listener) { 198 fAddFolderToBuildpathAction.addBuildpathModifierListener(listener); 199 fRemoveFromBuildpathAction.addBuildpathModifierListener(listener); 200 fExcludeFromBuildpathAction.addBuildpathModifierListener(listener); 201 fIncludeToBuildpathAction.addBuildpathModifierListener(listener); 202 fEditFilterAction.addBuildpathModifierListener(listener); 203 fEditOutputFolderAction.addBuildpathModifierListener(listener); 204 fCreateLinkedSourceFolderAction.addBuildpathModifierListener(listener); 205 fCreateSourceFolderAction.addBuildpathModifierListener(listener); 206 } 207 208 public void removeBuildpathModifierListener(IBuildpathModifierListener listener) { 209 fAddFolderToBuildpathAction.removeBuildpathModifierListener(listener); 210 fRemoveFromBuildpathAction.removeBuildpathModifierListener(listener); 211 fExcludeFromBuildpathAction.removeBuildpathModifierListener(listener); 212 fIncludeToBuildpathAction.removeBuildpathModifierListener(listener); 213 fEditFilterAction.removeBuildpathModifierListener(listener); 214 fEditOutputFolderAction.removeBuildpathModifierListener(listener); 215 fCreateLinkedSourceFolderAction.removeBuildpathModifierListener(listener); 216 fCreateSourceFolderAction.removeBuildpathModifierListener(listener); 217 } 218 219 227 public ToolBarManager createLeftToolBarManager(ViewerPane pane) { 228 ToolBarManager tbm= pane.getToolBarManager(); 229 230 tbm.add(fAddFolderToBuildpathAction); 231 tbm.add(fRemoveFromBuildpathAction); 232 tbm.add(new Separator()); 233 tbm.add(fExcludeFromBuildpathAction); 234 tbm.add(fIncludeToBuildpathAction); 235 tbm.add(new Separator()); 236 tbm.add(fDropDownAction); 237 238 tbm.update(true); 239 return tbm; 240 } 241 242 249 public ToolBarManager createLeftToolBar(ViewerPane pane) { 250 ToolBar tb= new ToolBar(pane, SWT.FLAT); 251 pane.setTopRight(tb); 252 ToolBarManager tbm= new ToolBarManager(tb); 253 254 tbm.add(fCreateLinkedSourceFolderAction); 255 tbm.add(fCreateSourceFolderAction); 256 tbm.add(fResetAllAction); 257 tbm.add(new HelpAction()); 258 259 tbm.update(true); 260 return tbm; 261 } 262 263 268 public void fillContextMenu(IMenuManager menu) { 269 270 if (fAddFolderToBuildpathAction.isEnabled()) 271 menu.add(fAddFolderToBuildpathAction); 272 273 if (fRemoveFromBuildpathAction.isEnabled()) 274 menu.add(fRemoveFromBuildpathAction); 275 276 if (fExcludeFromBuildpathAction.isEnabled()) 277 menu.add(fExcludeFromBuildpathAction); 278 279 if (fIncludeToBuildpathAction.isEnabled()) 280 menu.add(fIncludeToBuildpathAction); 281 282 if (fEditFilterAction.isEnabled()) 283 menu.add(fEditFilterAction); 284 285 if (fEditOutputFolderAction.isEnabled()) 286 menu.add(fEditOutputFolderAction); 287 288 if (fCreateLinkedSourceFolderAction.isEnabled()) 289 menu.add(fCreateLinkedSourceFolderAction); 290 291 if (fCreateSourceFolderAction.isEnabled()) 292 menu.add(fCreateSourceFolderAction); 293 294 super.fillContextMenu(menu); 295 } 296 297 public BuildpathModifierAction[] getHintTextGroupActions() { 298 List result= new ArrayList (); 299 300 if (fCreateSourceFolderAction.isEnabled()) 301 result.add(fCreateSourceFolderAction); 302 303 if (fCreateLinkedSourceFolderAction.isEnabled()) 304 result.add(fCreateLinkedSourceFolderAction); 305 306 if (fEditFilterAction.isEnabled()) 307 result.add(fEditFilterAction); 308 309 if (fExcludeFromBuildpathAction.isEnabled()) 310 result.add(fExcludeFromBuildpathAction); 311 312 if (fIncludeToBuildpathAction.isEnabled()) 313 result.add(fIncludeToBuildpathAction); 314 315 if (fEditOutputFolderAction.isEnabled()) 316 result.add(fEditOutputFolderAction); 317 318 if (fAddFolderToBuildpathAction.isEnabled()) 319 result.add(fAddFolderToBuildpathAction); 320 321 if (fRemoveFromBuildpathAction.isEnabled()) 322 result.add(fRemoveFromBuildpathAction); 323 324 return (BuildpathModifierAction[])result.toArray(new BuildpathModifierAction[result.size()]); 325 } 326 327 public EditOutputFolderAction getEditOutputFolderAction() { 328 return fEditOutputFolderAction; 329 } 330 331 public ResetAllAction getResetAllAction() { 332 return fResetAllAction; 333 } 334 } 335 | Popular Tags |