1 11 package org.eclipse.debug.internal.ui.launchConfigurations; 12 13 14 import org.eclipse.core.runtime.CoreException; 15 import org.eclipse.debug.core.DebugPlugin; 16 import org.eclipse.debug.core.ILaunchConfiguration; 17 import org.eclipse.debug.core.ILaunchConfigurationListener; 18 import org.eclipse.debug.core.ILaunchManager; 19 import org.eclipse.debug.internal.ui.DebugUIPlugin; 20 import org.eclipse.debug.internal.ui.IDebugHelpContextIds; 21 import org.eclipse.debug.internal.ui.SWTFactory; 22 import org.eclipse.debug.ui.AbstractDebugView; 23 import org.eclipse.debug.ui.IDebugUIConstants; 24 import org.eclipse.debug.ui.IDebugView; 25 import org.eclipse.help.HelpSystem; 26 import org.eclipse.help.IContext; 27 import org.eclipse.help.IContextProvider; 28 import org.eclipse.jface.action.IMenuManager; 29 import org.eclipse.jface.action.IToolBarManager; 30 import org.eclipse.jface.action.Separator; 31 import org.eclipse.jface.viewers.StructuredSelection; 32 import org.eclipse.jface.viewers.StructuredViewer; 33 import org.eclipse.jface.viewers.TreeViewer; 34 import org.eclipse.jface.viewers.Viewer; 35 import org.eclipse.jface.viewers.ViewerFilter; 36 import org.eclipse.swt.SWT; 37 import org.eclipse.swt.events.KeyAdapter; 38 import org.eclipse.swt.events.KeyEvent; 39 import org.eclipse.swt.widgets.Composite; 40 import org.eclipse.swt.widgets.Display; 41 import org.eclipse.swt.widgets.Label; 42 import org.eclipse.swt.widgets.Text; 43 import org.eclipse.ui.PlatformUI; 44 import org.eclipse.ui.dialogs.PatternFilter; 45 46 import com.ibm.icu.text.MessageFormat; 47 48 51 public class LaunchConfigurationView extends AbstractDebugView implements ILaunchConfigurationListener { 52 53 58 private LaunchConfigurationFilteredTree fTree; 59 60 65 private ILaunchManager fLaunchManager = DebugPlugin.getDefault().getLaunchManager(); 66 67 70 private LaunchGroupExtension fLaunchGroup; 71 72 75 private CreateLaunchConfigurationAction fCreateAction; 76 private DeleteLaunchConfigurationAction fDeleteAction; 77 private DuplicateLaunchConfigurationAction fDuplicateAction; 78 private CollapseAllLaunchConfigurationAction fCollapseAllAction; 79 80 84 private FilterLaunchConfigurationAction fFilterAction; 85 86 91 private Label fFilteredNotice = null; 92 93 96 private boolean fAutoSelect = true; 97 98 102 private ViewerFilter[] fFilters = null; 103 104 107 public LaunchConfigurationView(LaunchGroupExtension launchGroup) { 108 super(); 109 fLaunchGroup = launchGroup; 110 } 111 112 117 public LaunchConfigurationView(LaunchGroupExtension launchGroup, ViewerFilter[] filters) { 118 super(); 119 fLaunchGroup = launchGroup; 120 fFilters = filters; 121 } 122 123 128 protected LaunchGroupExtension getLaunchGroup() { 129 return fLaunchGroup; 130 } 131 132 135 protected Viewer createViewer(Composite parent) { 136 fTree = new LaunchConfigurationFilteredTree(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL, new PatternFilter(), fLaunchGroup, fFilters); 137 fTree.createViewControl(); 138 getLaunchManager().addLaunchConfigurationListener(this); 139 LaunchConfigurationViewer viewer = fTree.getLaunchConfigurationViewer(); 140 viewer.setLaunchConfigurationView(this); 141 return viewer; 142 } 143 144 147 public Object getAdapter(Class key) { 148 if (key == IContextProvider.class) { 149 return new IContextProvider () { 150 public int getContextChangeMask() { 151 return SELECTION; 152 } 153 154 public IContext getContext(Object target) { 155 String id = fTree.computeContextId(); 156 if (id!=null) 157 return HelpSystem.getContext(id); 158 return null; 159 } 160 161 public String getSearchExpression(Object target) { 162 return null; 163 } 164 }; 165 } 166 return super.getAdapter(key); 167 } 168 169 175 public Text getFilteringTextControl() { 176 return fTree.getFilterControl(); 177 } 178 179 182 protected void createActions() { 183 fCreateAction = new CreateLaunchConfigurationAction(getViewer(), getLaunchGroup().getMode()); 184 setAction(CreateLaunchConfigurationAction.ID_CREATE_ACTION, fCreateAction); 185 186 fDeleteAction = new DeleteLaunchConfigurationAction(getViewer(), getLaunchGroup().getMode()); 187 setAction(DeleteLaunchConfigurationAction.ID_DELETE_ACTION, fDeleteAction); 188 setAction(IDebugView.REMOVE_ACTION, fDeleteAction); 189 190 fDuplicateAction = new DuplicateLaunchConfigurationAction(getViewer(), getLaunchGroup().getMode()); 191 setAction(DuplicateLaunchConfigurationAction.ID_DUPLICATE_ACTION, fDuplicateAction); 192 193 fCollapseAllAction = new CollapseAllLaunchConfigurationAction((TreeViewer)getViewer()); 194 setAction(CollapseAllLaunchConfigurationAction.ID_COLLAPSEALL_ACTION, fCollapseAllAction); 195 196 fFilterAction = new FilterLaunchConfigurationAction(); 197 setAction(FilterLaunchConfigurationAction.ID_FILTER_ACTION, fFilterAction); 198 199 } 200 201 204 protected String getHelpContextId() { 205 return IDebugHelpContextIds.LAUNCH_CONFIGURATION_VIEW; 206 } 207 208 211 protected void fillContextMenu(IMenuManager menu) { 212 menu.add(fCreateAction); 213 menu.add(fDuplicateAction); 214 menu.add(fDeleteAction); 215 menu.add(new Separator()); 216 } 217 218 221 protected void configureToolBar(IToolBarManager tbm) {} 222 223 228 protected TreeViewer getTreeViewer() { 229 return fTree.getLaunchConfigurationViewer(); 230 } 231 232 235 public void dispose() { 236 fCreateAction.dispose(); 237 fDeleteAction.dispose(); 238 fDuplicateAction.dispose(); 239 fFilterAction = null; 240 fCollapseAllAction = null; 241 getLaunchManager().removeLaunchConfigurationListener(this); 242 } 243 244 247 public void launchConfigurationAdded(final ILaunchConfiguration configuration) { 248 try { 249 if (configuration.getAttribute(IDebugUIConstants.ATTR_PRIVATE, false)) { 250 return; 251 } 252 } catch (CoreException e) { 253 DebugUIPlugin.log(e); 254 return; 255 } 256 Display display = DebugUIPlugin.getStandardDisplay(); 257 if (display.getThread() == Thread.currentThread()) { 258 handleConfigurationAdded(configuration); 261 } else { 262 display.asyncExec(new Runnable () { 263 public void run() { 264 handleConfigurationAdded(configuration); 265 } 266 }); 267 } 268 } 269 270 274 private void handleConfigurationAdded(final ILaunchConfiguration configuration) { 275 TreeViewer viewer = getTreeViewer(); 276 if (viewer != null) { 277 try { 278 viewer.add(configuration.getType(), configuration); 279 ILaunchConfiguration from = getLaunchManager().getMovedFrom(configuration); 281 if (from != null) { 282 viewer.remove(from); 283 } 284 if (isAutoSelect()) { 285 viewer.setSelection(new StructuredSelection(configuration), true); 286 } 287 updateFilterLabel(); 288 } 289 catch (CoreException e) {} 290 } 291 } 292 293 296 public void launchConfigurationChanged(ILaunchConfiguration configuration) {} 297 298 301 public void launchConfigurationRemoved(final ILaunchConfiguration configuration) { 302 ILaunchConfiguration to = getLaunchManager().getMovedTo(configuration); 304 if (to != null) { 305 return; 306 } 307 Display display = DebugUIPlugin.getStandardDisplay(); 308 if (display.getThread() == Thread.currentThread()) { 309 handleConfigurationRemoved(configuration); 312 } else { 313 display.asyncExec(new Runnable () { 314 public void run() { 315 handleConfigurationRemoved(configuration); 316 } 317 }); 318 } 319 } 320 321 325 private void handleConfigurationRemoved(ILaunchConfiguration configuration) { 326 getTreeViewer().remove(configuration); 327 updateFilterLabel(); 328 } 329 330 336 public void createLaunchDialogControl(Composite parent) { 337 createViewer(parent); 338 createActions(); 339 createContextMenu(getViewer().getControl()); 340 PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, getHelpContextId()); 341 getViewer().getControl().addKeyListener(new KeyAdapter() { 342 public void keyPressed(KeyEvent e) { 343 handleKeyPressed(e); 344 } 345 }); 346 if (getViewer() instanceof StructuredViewer) { 347 ((StructuredViewer)getViewer()).addDoubleClickListener(this); 348 } 349 fFilteredNotice = SWTFactory.createLabel(parent, "", 1); fFilteredNotice.setBackground(parent.getBackground()); 351 } 352 353 356 public Viewer getViewer() { 357 return fTree.getLaunchConfigurationViewer(); 358 } 359 360 364 public void updateFilterLabel() { 365 LaunchConfigurationViewer viewer = (LaunchConfigurationViewer) getViewer(); 366 fFilteredNotice.setText(MessageFormat.format(LaunchConfigurationsMessages.LaunchConfigurationView_0, new String [] {Integer.toString(viewer.getNonFilteredChildCount()), Integer.toString(viewer.getTotalChildCount())})); 367 } 368 369 373 protected ILaunchManager getLaunchManager() { 374 return fLaunchManager; 375 } 376 377 384 public void setAutoSelect(boolean select) { 385 fAutoSelect = select; 386 } 387 388 396 protected boolean isAutoSelect() { 397 return fAutoSelect; 398 } 399 } 400 | Popular Tags |