1 /* 2 * Copyright (C) 2007 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; 18 19 20 import org.eclipse.jface.text.IAutoEditStrategy; 21 import org.eclipse.jface.text.IDocument; 22 import org.eclipse.jface.text.ITextHover; 23 import org.eclipse.jface.text.contentassist.IContentAssistProcessor; 24 import org.eclipse.jface.text.contentassist.IContentAssistant; 25 import org.eclipse.jface.text.formatter.IContentFormatter; 26 import org.eclipse.jface.text.source.ISourceViewer; 27 import org.eclipse.jface.viewers.IInputProvider; 28 import org.eclipse.wst.sse.core.text.IStructuredPartitions; 29 import org.eclipse.wst.xml.core.text.IXMLPartitions; 30 import org.eclipse.wst.xml.ui.StructuredTextViewerConfigurationXML; 31 32 import java.util.ArrayList; 33 34 /** 35 * Base Source Viewer Configuration for Android resources. 36 */ 37 public class AndroidSourceViewerConfig extends StructuredTextViewerConfigurationXML { 38 39 /** Content Assist Processor to use for all handled partitions. */ 40 private IContentAssistProcessor mProcessor; 41 AndroidSourceViewerConfig(IContentAssistProcessor processor)42 public AndroidSourceViewerConfig(IContentAssistProcessor processor) { 43 super(); 44 mProcessor = processor; 45 } 46 47 @Override getContentAssistant(ISourceViewer sourceViewer)48 public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) { 49 return super.getContentAssistant(sourceViewer); 50 } 51 52 /** 53 * Returns the content assist processors that will be used for content 54 * assist in the given source viewer and for the given partition type. 55 * 56 * @param sourceViewer the source viewer to be configured by this 57 * configuration 58 * @param partitionType the partition type for which the content assist 59 * processors are applicable 60 * @return IContentAssistProcessors or null if should not be supported 61 */ 62 @Override getContentAssistProcessors( ISourceViewer sourceViewer, String partitionType)63 protected IContentAssistProcessor[] getContentAssistProcessors( 64 ISourceViewer sourceViewer, String partitionType) { 65 ArrayList<IContentAssistProcessor> processors = new ArrayList<IContentAssistProcessor>(); 66 if (partitionType == IStructuredPartitions.UNKNOWN_PARTITION || 67 partitionType == IStructuredPartitions.DEFAULT_PARTITION || 68 partitionType == IXMLPartitions.XML_DEFAULT) { 69 if (sourceViewer instanceof IInputProvider) { 70 IInputProvider input = (IInputProvider) sourceViewer; 71 Object a = input.getInput(); 72 if (a != null) 73 a.toString(); 74 } 75 76 IDocument doc = sourceViewer.getDocument(); 77 if (doc != null) 78 doc.toString(); 79 80 processors.add(mProcessor); 81 } 82 83 IContentAssistProcessor[] others = super.getContentAssistProcessors(sourceViewer, 84 partitionType); 85 if (others != null && others.length > 0) { 86 for (IContentAssistProcessor p : others) { 87 processors.add(p); 88 } 89 } 90 91 if (processors.size() > 0) { 92 return processors.toArray(new IContentAssistProcessor[processors.size()]); 93 } else { 94 return null; 95 } 96 } 97 98 @Override getTextHover(ISourceViewer sourceViewer, String contentType)99 public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) { 100 // TODO text hover for android xml 101 return super.getTextHover(sourceViewer, contentType); 102 } 103 104 @Override getAutoEditStrategies( ISourceViewer sourceViewer, String contentType)105 public IAutoEditStrategy[] getAutoEditStrategies( 106 ISourceViewer sourceViewer, String contentType) { 107 // TODO auto edit strategies for android xml 108 return super.getAutoEditStrategies(sourceViewer, contentType); 109 } 110 111 @Override getContentFormatter(ISourceViewer sourceViewer)112 public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) { 113 // TODO content formatter for android xml 114 return super.getContentFormatter(sourceViewer); 115 } 116 } 117