org.chromium.debug.ui/src/org/chromium/debug/ui/source/SourceNameMapperContainerPresentation.java
changeset 355 8726e95bcbba
equal deleted inserted replaced
354:0bceeb415e7f 355:8726e95bcbba
       
     1 // Copyright (c) 2010 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.source;
       
     6 
       
     7 import org.chromium.debug.core.SourceNameMapperContainer;
       
     8 import org.eclipse.debug.core.sourcelookup.ISourceContainer;
       
     9 import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector;
       
    10 import org.eclipse.debug.ui.sourcelookup.ISourceContainerBrowser;
       
    11 import org.eclipse.swt.widgets.Shell;
       
    12 
       
    13 /**
       
    14  * A presentation for JavaScript Source Name Mapper container that supports adding and editing.
       
    15  */
       
    16 public class SourceNameMapperContainerPresentation implements ISourceContainerBrowser {
       
    17 
       
    18   public ISourceContainer[] addSourceContainers(Shell shell, ISourceLookupDirector director) {
       
    19     return openDialog(shell, director, null);
       
    20   }
       
    21 
       
    22   public boolean canAddSourceContainers(ISourceLookupDirector director) {
       
    23     return true;
       
    24   }
       
    25 
       
    26   public boolean canEditSourceContainers(ISourceLookupDirector director,
       
    27       ISourceContainer[] containers) {
       
    28     return containers.length == 1;
       
    29   }
       
    30 
       
    31   public ISourceContainer[] editSourceContainers(Shell shell, ISourceLookupDirector director,
       
    32       ISourceContainer[] containers) {
       
    33     final SourceNameMapperContainer originalContainer = (SourceNameMapperContainer) containers[0];
       
    34     SourceNameMapperContainerDialog.PresetFieldValues params =
       
    35         new SourceNameMapperContainerDialog.PresetFieldValues() {
       
    36       public ISourceContainer getContainer() {
       
    37         return originalContainer.getTargetContainer();
       
    38       }
       
    39       public String getPrefix() {
       
    40         return originalContainer.getPrefix();
       
    41       }
       
    42     };
       
    43 
       
    44     return openDialog(shell, director, params);
       
    45   }
       
    46 
       
    47   private ISourceContainer[] openDialog(Shell shell, ISourceLookupDirector director,
       
    48       SourceNameMapperContainerDialog.PresetFieldValues params) {
       
    49     SourceNameMapperContainerDialog dialog =
       
    50         new SourceNameMapperContainerDialog(shell, director, params);
       
    51     dialog.open();
       
    52     SourceNameMapperContainerDialog.Result dialogResult = dialog.getResult();
       
    53     if (dialogResult == null) {
       
    54       return new ISourceContainer[0];
       
    55     }
       
    56     ISourceContainer result = new SourceNameMapperContainer(dialogResult.getResultPrefix(),
       
    57         dialogResult.getResultContainer());
       
    58     return new ISourceContainer[] { result };
       
    59   }
       
    60 }