Home | History | Annotate | Download | only in common
      1 /*
      2  * Copyright (C) 2012 The Android Open Source Project
      3  *
      4  * Licensed under the Eclipse Public License, Version 1.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.eclipse.org/org/documents/epl-v10.php
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package com.android.ide.eclipse.adt.internal.editors.common;
     18 
     19 import com.android.ide.eclipse.adt.internal.editors.AndroidSourceViewerConfig;
     20 
     21 import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
     22 import org.eclipse.jface.text.source.ISourceViewer;
     23 
     24 
     25 
     26 /**
     27  * Source Viewer Configuration for the Common XML editor.
     28  * Everything is already generic and done in the base class.
     29  * The base class will use the delegate to find out the proper content assist to use.
     30  */
     31 public final class CommonSourceViewerConfig extends AndroidSourceViewerConfig {
     32 
     33     private final IContentAssistProcessor mContentAssist;
     34 
     35     public CommonSourceViewerConfig() {
     36         super();
     37         mContentAssist = null;
     38     }
     39 
     40     public CommonSourceViewerConfig(IContentAssistProcessor contentAssist) {
     41         super();
     42         mContentAssist = contentAssist;
     43     }
     44 
     45 
     46     /**
     47      * @return The {@link IContentAssistProcessor} passed to the constructor or null.
     48      */
     49     @Override
     50     public IContentAssistProcessor getAndroidContentAssistProcessor(
     51             ISourceViewer sourceViewer,
     52             String partitionType) {
     53         // You may think you could use AndroidXmlEditor.fromTextViewer(sourceViewer)
     54         // to find the editor associated with the sourceViewer and then access the
     55         // delegate and query the content assist specific to a given delegate.
     56         // Unfortunately this is invoked whilst the editor part is being created
     57         // so we can't match an existing editor to the source view -- since there
     58         // is no such "existing" editor. It's just being created.
     59         //
     60         // As a workaround, CommonXmlEditor#addPages() will unconfigure the
     61         // default sourceViewerConfig and reconfigure it with one that really
     62         // knows which content assist it should be using.
     63 
     64         return mContentAssist;
     65     }
     66 }
     67