org.chromium.debug.core/src/org/chromium/debug/core/VProjectSourceContainer.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.core;
       
     6 
       
     7 import org.chromium.debug.core.model.ResourceManager;
       
     8 import org.chromium.debug.core.model.VmResourceId;
       
     9 import org.eclipse.core.resources.IFile;
       
    10 import org.eclipse.core.resources.IProject;
       
    11 import org.eclipse.core.runtime.CoreException;
       
    12 import org.eclipse.debug.core.DebugPlugin;
       
    13 import org.eclipse.debug.core.sourcelookup.ISourceContainer;
       
    14 import org.eclipse.debug.core.sourcelookup.ISourceContainerType;
       
    15 import org.eclipse.debug.core.sourcelookup.ISourceContainerTypeDelegate;
       
    16 import org.eclipse.debug.core.sourcelookup.ISourceLookupDirector;
       
    17 
       
    18 /**
       
    19  * A source container implementation that wraps V8 virtual project. Currently virtual project
       
    20  * has a flat file structure, so the container is accordingly one-level.
       
    21  * <p>
       
    22  * Unlike other implementation of {@link ISourceContainer} this class initially gets instantiated
       
    23  * with no data. In this state it serves as an empty container because actual VM scripts are
       
    24  * not available yet. Launch configuration UI will use it in this state more as a symbolic
       
    25  * place-holder in sources tab. Later when VM is connected, method
       
    26  * {@link #init(ISourceLookupDirector)} will be called and the actual content will be set.
       
    27  */
       
    28 public class VProjectSourceContainer implements ISourceContainer {
       
    29 
       
    30   private static final String TYPE_ID =
       
    31       "org.chromium.debug.core.VProjectSourceContainer.type"; //$NON-NLS-1$
       
    32 
       
    33   private ChromiumSourceDirector chromiumSourceDirector = null;
       
    34 
       
    35   VProjectSourceContainer() {
       
    36   }
       
    37 
       
    38   public void init(ISourceLookupDirector director) {
       
    39     if (director instanceof ChromiumSourceDirector) {
       
    40       chromiumSourceDirector = (ChromiumSourceDirector) director;
       
    41     }
       
    42   }
       
    43 
       
    44   public void dispose() {
       
    45   }
       
    46 
       
    47   public Object[] findSourceElements(String name) {
       
    48     if (chromiumSourceDirector == null) {
       
    49       return new Object[0];
       
    50     }
       
    51     ResourceManager resourceManager = chromiumSourceDirector.getResourceManager();
       
    52     IFile file = resourceManager.getFile(name);
       
    53     if (file == null) {
       
    54       return new Object[0];
       
    55     }
       
    56     return new Object[] { file };
       
    57   }
       
    58 
       
    59   public String getName() {
       
    60     IProject project = null;
       
    61     if (chromiumSourceDirector != null) {
       
    62       project = chromiumSourceDirector.getProject();
       
    63     }
       
    64     if (project == null) {
       
    65       return Messages.VProjectSourceContainer_DEFAULT_TYPE_NAME;
       
    66     } else {
       
    67       return project.getName();
       
    68     }
       
    69   }
       
    70 
       
    71   public ISourceContainer[] getSourceContainers() {
       
    72     return null;
       
    73   }
       
    74 
       
    75   public ISourceContainerType getType() {
       
    76     return DebugPlugin.getDefault().getLaunchManager().getSourceContainerType(TYPE_ID);
       
    77   }
       
    78 
       
    79   public boolean isComposite() {
       
    80     return false;
       
    81   }
       
    82 
       
    83   public VmResourceId findScriptId(IFile resource) {
       
    84     if (chromiumSourceDirector == null) {
       
    85       throw new IllegalStateException();
       
    86     }
       
    87     return chromiumSourceDirector.getResourceManager().getResourceId(resource);
       
    88   }
       
    89 
       
    90   public Object getAdapter(Class adapter) {
       
    91     return null;
       
    92   }
       
    93 
       
    94   /**
       
    95    * A type delegate that implements a trivial memento. We do not save any actual data here,
       
    96    * because it all should be derived from a current VM launch.
       
    97    */
       
    98   public static class TypeDelegate implements ISourceContainerTypeDelegate {
       
    99     public ISourceContainer createSourceContainer(String memento) throws CoreException {
       
   100       return new VProjectSourceContainer();
       
   101     }
       
   102 
       
   103     public String getMemento(ISourceContainer container) throws CoreException {
       
   104       return "VProjectSourceContainer.memento.stub"; //$NON-NLS-1$
       
   105     }
       
   106   }
       
   107 }