Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 352502 | Differences between
and this patch

Collapse All | Expand All

(-)ui/org/eclipse/debug/internal/ui/actions/ToggleBreakpointsTargetManager.java (-24 / +55 lines)
Lines 23-28 Link Here
23
import java.util.Map.Entry;
23
import java.util.Map.Entry;
24
import java.util.Set;
24
import java.util.Set;
25
import java.util.StringTokenizer;
25
import java.util.StringTokenizer;
26
import java.util.TreeMap;
27
import java.util.TreeSet;
26
28
27
import org.eclipse.core.expressions.EvaluationResult;
29
import org.eclipse.core.expressions.EvaluationResult;
28
import org.eclipse.core.expressions.Expression;
30
import org.eclipse.core.expressions.Expression;
Lines 96-102 Link Here
96
        }
98
        }
97
99
98
        /**
100
        /**
99
         * Returns the instantiated factory specified by the class property. 
101
         * @return Returns the instantiated factory specified by the class property. 
100
         */
102
         */
101
        private IToggleBreakpointsTargetFactory getFactory() {
103
        private IToggleBreakpointsTargetFactory getFactory() {
102
            if (fFactory != null) return fFactory;
104
            if (fFactory != null) return fFactory;
Lines 117-122 Link Here
117
        /**
119
        /**
118
         * Checks if the enablement expression for the factory evaluates to true for the
120
         * Checks if the enablement expression for the factory evaluates to true for the
119
         * given part and selection.
121
         * given part and selection.
122
         * @param part The active part.
123
         * @param selection The current selection
124
         * @return whether the delegated target factory is enabled for given 
125
         * part and selection.
120
         */
126
         */
121
        public boolean isEnabled(IWorkbenchPart part, ISelection selection) {
127
        public boolean isEnabled(IWorkbenchPart part, ISelection selection) {
122
            boolean enabled = false;
128
            boolean enabled = false;
Lines 181-187 Link Here
181
        }
187
        }
182
        
188
        
183
        /**
189
        /**
184
         * Returns an expression that represents the enablement logic for the
190
         * @return Returns an expression that represents the enablement logic for the
185
         * breakpiont toggle target.
191
         * breakpiont toggle target.
186
         */
192
         */
187
        private Expression getEnablementExpression(){
193
        private Expression getEnablementExpression(){
Lines 203-208 Link Here
203
        /** 
209
        /** 
204
         * Instantiates the factory and asks it to produce the IToggleBreakpointsTarget
210
         * Instantiates the factory and asks it to produce the IToggleBreakpointsTarget
205
         * for the given ID
211
         * for the given ID
212
         * @param targetID ID to create toggle target for 
213
         * @return The created toggle target, or null.
206
         */
214
         */
207
        public IToggleBreakpointsTarget createToggleTarget(String targetID) {
215
        public IToggleBreakpointsTarget createToggleTarget(String targetID) {
208
            IToggleBreakpointsTargetFactory factory = getFactory();
216
            IToggleBreakpointsTargetFactory factory = getFactory();
Lines 215-220 Link Here
215
        /** 
223
        /** 
216
         * Instantiates the factory and asks it for the set of toggle target
224
         * Instantiates the factory and asks it for the set of toggle target
217
         * IDs that the factory can produce for the given part and selection.
225
         * IDs that the factory can produce for the given part and selection.
226
         * @param part The active part.
227
         * @param selection The current selection
228
         * @return Set of <code>String</code> IDs for possible toggle breakpoint 
229
         * targets, possibly empty
218
         */
230
         */
219
        public Set getToggleTargets(IWorkbenchPart part, ISelection selection) {
231
        public Set getToggleTargets(IWorkbenchPart part, ISelection selection) {
220
            IToggleBreakpointsTargetFactory factory = getFactory();
232
            IToggleBreakpointsTargetFactory factory = getFactory();
Lines 227-232 Link Here
227
        /** 
239
        /** 
228
         * Instantiates the factory and asks it to produce the name of the toggle target
240
         * Instantiates the factory and asks it to produce the name of the toggle target
229
         * for the given ID.
241
         * for the given ID.
242
         * @param targetID toggle breakpoints target identifier
243
         * @return toggle target name
230
         */
244
         */
231
        public String getToggleTargetName(String targetID) {
245
        public String getToggleTargetName(String targetID) {
232
            IToggleBreakpointsTargetFactory factory = getFactory();
246
            IToggleBreakpointsTargetFactory factory = getFactory();
Lines 239-244 Link Here
239
        /** 
253
        /** 
240
         * Instantiates the factory and asks it to produce the description of the toggle 
254
         * Instantiates the factory and asks it to produce the description of the toggle 
241
         * target for the given ID.
255
         * target for the given ID.
256
         * @param targetID toggle breakpoints target identifier
257
         * @return toggle target name or <code>null</code> if none
242
         */
258
         */
243
        public String getToggleTargetDescription(String targetID) {
259
        public String getToggleTargetDescription(String targetID) {
244
            IToggleBreakpointsTargetFactory factory = getFactory();
260
            IToggleBreakpointsTargetFactory factory = getFactory();
Lines 251-256 Link Here
251
        /** 
267
        /** 
252
         * Instantiates the factory and asks it for the toggle tareget ID that
268
         * Instantiates the factory and asks it for the toggle tareget ID that
253
         * the factory considers the default for the given part and selection.
269
         * the factory considers the default for the given part and selection.
270
         * @param part The active part.
271
         * @param selection The current selection
272
         * @return a breakpoint toggle target identifier or <code>null</code>
254
         */
273
         */
255
        public String getDefaultToggleTarget(IWorkbenchPart part, ISelection selection) { 
274
        public String getDefaultToggleTarget(IWorkbenchPart part, ISelection selection) { 
256
            IToggleBreakpointsTargetFactory factory = getFactory();
275
            IToggleBreakpointsTargetFactory factory = getFactory();
Lines 302-309 Link Here
302
         * It first looks for the target using the factories registered using an 
321
         * It first looks for the target using the factories registered using an 
303
         * extension point.  If not found it uses the <code>IAdaptable</code>
322
         * extension point.  If not found it uses the <code>IAdaptable</code>
304
         * mechanism.
323
         * mechanism.
305
         * @param part active part
324
         * @param adaptable The adaptable object to retrieve the toggle adapter from
306
         * @param selection active selection in part
307
         * @return The toggle breakpoints target, or <code>null</code> if not found.
325
         * @return The toggle breakpoints target, or <code>null</code> if not found.
308
         */
326
         */
309
        private IToggleBreakpointsTarget getToggleBreakpointsTarget(IAdaptable adaptable) {
327
        private IToggleBreakpointsTarget getToggleBreakpointsTarget(IAdaptable adaptable) {
Lines 327-332 Link Here
327
         * Checks if there is an adaptable object for the given part and 
345
         * Checks if there is an adaptable object for the given part and 
328
         * selection, and if there is, it checks whether an 
346
         * selection, and if there is, it checks whether an 
329
         * <code>IToggleBreakpointsTarget</code> can be obtained as an adapter.
347
         * <code>IToggleBreakpointsTarget</code> can be obtained as an adapter.
348
         * @param part The workbench part in which toggle target is to be used
349
         * @param selection The active selection to use with toggle target
350
         * @return Whether the adapter (default) toggle target is available. 
330
         */
351
         */
331
        public boolean isEnabled(IWorkbenchPart part, ISelection selection) {
352
        public boolean isEnabled(IWorkbenchPart part, ISelection selection) {
332
            IAdaptable adaptable = getAdaptable(part, selection);
353
            IAdaptable adaptable = getAdaptable(part, selection);
Lines 336-348 Link Here
336
        /**
357
        /**
337
         * Not implemented use {@link #createDefaultToggleTarget(IWorkbenchPart, ISelection)}
358
         * Not implemented use {@link #createDefaultToggleTarget(IWorkbenchPart, ISelection)}
338
         * instead.
359
         * instead.
360
         * @param targetID not used
361
         * @return always returns null
339
         */
362
         */
340
        public IToggleBreakpointsTarget createToggleTarget(String targetID) {
363
        public IToggleBreakpointsTarget createToggleTarget(String targetID) {
341
            return null;
364
            return null;
342
        }
365
        }
343
        
366
        
344
        /**
367
        /**
345
         * Returns a toggle target for the given part and selection, obtained 
368
         * @param part The workbench part in which toggle target is to be used
369
         * @param selection The active selection to use with toggle target
370
         * @return Returns a toggle target for the given part and selection, obtained 
346
         * through the adapter mechanism. 
371
         * through the adapter mechanism. 
347
         */
372
         */
348
        public IToggleBreakpointsTarget createDefaultToggleTarget(IWorkbenchPart part, ISelection selection) {
373
        public IToggleBreakpointsTarget createDefaultToggleTarget(IWorkbenchPart part, ISelection selection) {
Lines 374-381 Link Here
374
    
399
    
375
    /**
400
    /**
376
     * Preference key for storing the preferred targets map.
401
     * Preference key for storing the preferred targets map.
377
     * @see {@link #storePreferredTargets()}
402
     * @see #storePreferredTargets()
378
     * @see {@link #loadPreferredTargets()}
403
     * @see #loadPreferredTargets()
379
     */
404
     */
380
    public static final String PREF_TARGETS = "preferredTargets"; //$NON-NLS-1$
405
    public static final String PREF_TARGETS = "preferredTargets"; //$NON-NLS-1$
381
406
Lines 405-411 Link Here
405
     * Maps the IDs of toggle targets to the factory that can create them.
430
     * Maps the IDs of toggle targets to the factory that can create them.
406
     * There can currently only be one factory for a given toggle target.
431
     * There can currently only be one factory for a given toggle target.
407
     */
432
     */
408
    private Map fFactoriesByTargetID = new HashMap();
433
    private Map fFactoriesByTargetID = new TreeMap();
409
    
434
    
410
    /**
435
    /**
411
     * List of listeners to changes in the preferred toggle targets list.
436
     * List of listeners to changes in the preferred toggle targets list.
Lines 454-460 Link Here
454
    private Set getEnabledFactories(IWorkbenchPart part, ISelection selection) {
479
    private Set getEnabledFactories(IWorkbenchPart part, ISelection selection) {
455
        if (fKnownFactories == null) initializeFactories();
480
        if (fKnownFactories == null) initializeFactories();
456
481
457
        Set set = new LinkedHashSet();
482
        Set set = new TreeSet();
458
        for (Iterator itr = fKnownFactories.keySet().iterator(); itr.hasNext(); ) {
483
        for (Iterator itr = fKnownFactories.keySet().iterator(); itr.hasNext(); ) {
459
            String id = (String)itr.next();
484
            String id = (String)itr.next();
460
            IToggleBreakpointsTargetFactory factory = (IToggleBreakpointsTargetFactory)fKnownFactories.get(id);
485
            IToggleBreakpointsTargetFactory factory = (IToggleBreakpointsTargetFactory)fKnownFactories.get(id);
Lines 516-529 Link Here
516
    public String getPreferredToggleBreakpointsTargetID(IWorkbenchPart part, ISelection selection) {
541
    public String getPreferredToggleBreakpointsTargetID(IWorkbenchPart part, ISelection selection) {
517
        Set factories = getEnabledFactories(part, selection);
542
        Set factories = getEnabledFactories(part, selection);
518
        Set possibleIDs = getEnabledTargetIDs(factories, part, selection);
543
        Set possibleIDs = getEnabledTargetIDs(factories, part, selection);
519
        return chooseToggleTargetIDInSet(possibleIDs, factories, part, selection);
544
        return chooseToggleTargetIDInSet(possibleIDs, part, selection);
520
    }
545
    }
521
546
522
    /**
547
    /**
523
     * Given the ID of toggle breakpoint target, this method will try to find the factory
548
     * Given the ID of toggle breakpoint target, this method will try to find the factory
524
     * that creates it and return an instance of it.
549
     * that creates it and return an instance of it.
525
     * 
550
     * 
526
     * @param ID The ID of the requested toggle breakpoint target.
551
     * @param part The workbench part in which toggle target is to be used
552
     * @param selection The active selection to use with toggle target 
527
     * @return The instantiated target or null
553
     * @return The instantiated target or null
528
     */
554
     */
529
    public IToggleBreakpointsTarget getToggleBreakpointsTarget(IWorkbenchPart part, ISelection selection) {
555
    public IToggleBreakpointsTarget getToggleBreakpointsTarget(IWorkbenchPart part, ISelection selection) {
Lines 543-549 Link Here
543
     * Given the ID of a toggle breakpoints target, this method will try 
569
     * Given the ID of a toggle breakpoints target, this method will try 
544
     * to find the factory that creates it and ask it for the name of it.
570
     * to find the factory that creates it and ask it for the name of it.
545
     * 
571
     * 
546
     * @param ID The ID of the requested toggle breakpoint target.
572
     * @param id The ID of the requested toggle breakpoint target.
547
     * @return The name of the target.
573
     * @return The name of the target.
548
     */
574
     */
549
    public String getToggleBreakpointsTargetName(String id) {
575
    public String getToggleBreakpointsTargetName(String id) {
Lines 558-564 Link Here
558
     * Given the ID of a toggle breakpoints target, this method will try 
584
     * Given the ID of a toggle breakpoints target, this method will try 
559
     * to find the factory that creates it and ask it for the description of it.
585
     * to find the factory that creates it and ask it for the description of it.
560
     * 
586
     * 
561
     * @param ID The ID of the requested toggle breakpoint target.
587
     * @param id The ID of the requested toggle breakpoint target.
562
     * @return The description of the target or null.
588
     * @return The description of the target or null.
563
     */
589
     */
564
    public String getToggleBreakpointsTargetDescription(String id) {
590
    public String getToggleBreakpointsTargetDescription(String id) {
Lines 659-667 Link Here
659
    }
685
    }
660
    
686
    
661
    /**
687
    /**
662
     * Returns the preferred pane ID from the given set if the mapping has been set.
688
     * Returns the preferred toggle target ID from the given set if the mapping has been set.
663
     * 
689
     * 
664
     * @param possibleDetailsAreaIDs Set of possible pane IDs
690
     * @param possibleTargetIDs The set of possible toggle target IDs
665
     * @return The preferred ID or null
691
     * @return The preferred ID or null
666
     */
692
     */
667
    private String getUserPreferredTarget(Set possibleTargetIDs){
693
    private String getUserPreferredTarget(Set possibleTargetIDs){
Lines 672-685 Link Here
672
    }
698
    }
673
699
674
    /**
700
    /**
675
     * Given a set of possible detail pane IDs, this method will determine which pane is
701
     * Given a set of possible toggle target IDs, this method will determine which target is
676
     * preferred and should be used to display the selection.  This method chooses a pane
702
     * preferred and should be used to toggle breakpoints.  This method chooses a toggle target
677
     * by storing previous choices and can be set using a context menu.
703
     * by storing previous choices and can be set using a context menu.
678
     * 
704
     * 
679
     * @param possiblePaneIDs The set of possible detail pane IDs
705
     * @param possibleTargetIDs The set of possible toggle target IDs
680
     * @return The preferred detail pane ID or null
706
     * @param part The workbench part in which toggle target is to be used
707
     * @param selection The active selection to use with toggle target 
708
     * @return The preferred toggle target ID or null
681
     */
709
     */
682
    private String chooseToggleTargetIDInSet(Set possibleTargetIDs, Collection enabledFactories, IWorkbenchPart part, ISelection selection){
710
    private String chooseToggleTargetIDInSet(Set possibleTargetIDs, IWorkbenchPart part, ISelection selection){
683
        if (possibleTargetIDs == null || possibleTargetIDs.isEmpty()){
711
        if (possibleTargetIDs == null || possibleTargetIDs.isEmpty()){
684
            return null;
712
            return null;
685
        }
713
        }
Lines 688-697 Link Here
688
        
716
        
689
        if (preferredID == null){
717
        if (preferredID == null){
690
            // If there is no preferred pane already set, check the factories to see there is a default target
718
            // If there is no preferred pane already set, check the factories to see there is a default target
691
            Iterator factoryIterator = enabledFactories.iterator();
719
            Iterator possibleIDsIterator = possibleTargetIDs.iterator();
692
            while (preferredID == null && factoryIterator.hasNext()) {
720
            while (preferredID == null && possibleIDsIterator.hasNext()) {
693
                IToggleBreakpointsTargetFactory currentFactory = (IToggleBreakpointsTargetFactory) factoryIterator.next();
721
            	IToggleBreakpointsTargetFactory factory = (IToggleBreakpointsTargetFactory)
694
                preferredID = currentFactory.getDefaultToggleTarget(part, selection);
722
            			fFactoriesByTargetID.get(possibleIDsIterator.next());
723
            	if (factory != null) {
724
            		preferredID = factory.getDefaultToggleTarget(part, selection);
725
            	}
695
            }
726
            }
696
            // If the factories don't have a default, just pick the first one.
727
            // If the factories don't have a default, just pick the first one.
697
            if (preferredID == null) {
728
            if (preferredID == null) {

Return to bug 352502