org.chromium.debug.ui/src/org/chromium/debug/ui/actions/JsBreakpointPropertiesAction.java
changeset 355 8726e95bcbba
equal deleted inserted replaced
354:0bceeb415e7f 355:8726e95bcbba
       
     1 // Copyright (c) 20109 The Chromium Authors. All rights reserved.
       
     2 // Use of this source code is governed by a BSD-style license that can be
       
     3 // found in the LICENSE file.
       
     4 
       
     5 package org.chromium.debug.ui.actions;
       
     6 
       
     7 import org.chromium.debug.core.model.ChromiumLineBreakpoint;
       
     8 import org.eclipse.debug.core.model.IBreakpoint;
       
     9 import org.eclipse.jface.action.IAction;
       
    10 import org.eclipse.jface.viewers.ISelection;
       
    11 import org.eclipse.jface.viewers.ISelectionChangedListener;
       
    12 import org.eclipse.jface.viewers.ISelectionProvider;
       
    13 import org.eclipse.jface.viewers.IStructuredSelection;
       
    14 import org.eclipse.jface.viewers.StructuredSelection;
       
    15 import org.eclipse.jface.window.IShellProvider;
       
    16 import org.eclipse.ui.IObjectActionDelegate;
       
    17 import org.eclipse.ui.IWorkbenchPart;
       
    18 import org.eclipse.ui.IWorkbenchPartSite;
       
    19 import org.eclipse.ui.dialogs.PropertyDialogAction;
       
    20 
       
    21 /**
       
    22  * Action to bring up the breakpoint properties dialog.
       
    23  */
       
    24 public class JsBreakpointPropertiesAction implements IObjectActionDelegate {
       
    25 
       
    26   private Runnable currentRunnable;
       
    27   private IWorkbenchPartSite site = null;
       
    28 
       
    29   public void setActivePart(IAction action, IWorkbenchPart targetPart) {
       
    30     site = targetPart.getSite();
       
    31   }
       
    32 
       
    33   public void run(IAction action) {
       
    34     currentRunnable.run();
       
    35   }
       
    36 
       
    37   public void selectionChanged(IAction action, ISelection selection) {
       
    38     currentRunnable = createRunnable(selection);
       
    39     action.setEnabled(currentRunnable != null);
       
    40   }
       
    41 
       
    42 
       
    43   private Runnable createRunnable(ISelection selection) {
       
    44     if (selection instanceof IStructuredSelection == false) {
       
    45       return null;
       
    46     }
       
    47     IStructuredSelection structuredSelection = (IStructuredSelection) selection;
       
    48     if (structuredSelection.size() != 1) {
       
    49       return null;
       
    50     }
       
    51     Object element = structuredSelection.getFirstElement();
       
    52     if (element instanceof ChromiumLineBreakpoint == false) {
       
    53       return null;
       
    54     }
       
    55     final ChromiumLineBreakpoint breakpoint = (ChromiumLineBreakpoint) element;
       
    56 
       
    57     return new Runnable() {
       
    58       public void run() {
       
    59         runAction(breakpoint, site);
       
    60       }
       
    61     };
       
    62   }
       
    63 
       
    64   protected static void runAction(final IBreakpoint breakpoint, IShellProvider shell) {
       
    65     PropertyDialogAction action =
       
    66       new PropertyDialogAction(shell,
       
    67           new ISelectionProvider() {
       
    68             public void addSelectionChangedListener(ISelectionChangedListener listener) {
       
    69             }
       
    70 
       
    71             public ISelection getSelection() {
       
    72               return new StructuredSelection(breakpoint);
       
    73             }
       
    74 
       
    75             public void removeSelectionChangedListener(ISelectionChangedListener listener) {
       
    76             }
       
    77 
       
    78             public void setSelection(ISelection selection) {
       
    79             }
       
    80           });
       
    81     action.run();
       
    82   }
       
    83 }