testdev/ite/src/com.nokia.testfw.stf.scripteditor/src/com/nokia/testfw/stf/scripteditor/editors/ScriptEditorConfiguration.java
changeset 1 96906a986c3b
equal deleted inserted replaced
0:f1112f777ce9 1:96906a986c3b
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 package com.nokia.testfw.stf.scripteditor.editors;
       
    20 
       
    21 import java.util.ArrayList;
       
    22 
       
    23 import org.eclipse.jface.preference.IPreferenceStore;
       
    24 import org.eclipse.jface.text.DefaultTextHover;
       
    25 import org.eclipse.jface.text.IDocument;
       
    26 import org.eclipse.jface.text.IRegion;
       
    27 import org.eclipse.jface.text.ITextHover;
       
    28 import org.eclipse.jface.text.ITextViewer;
       
    29 import org.eclipse.jface.text.contentassist.ContentAssistant;
       
    30 import org.eclipse.jface.text.contentassist.IContentAssistant;
       
    31 import org.eclipse.jface.text.presentation.IPresentationReconciler;
       
    32 import org.eclipse.jface.text.presentation.PresentationReconciler;
       
    33 import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
       
    34 import org.eclipse.jface.text.source.DefaultAnnotationHover;
       
    35 import org.eclipse.jface.text.source.IAnnotationHover;
       
    36 import org.eclipse.jface.text.source.ISourceViewer;
       
    37 import org.eclipse.jface.text.source.SourceViewerConfiguration;
       
    38 
       
    39 import com.nokia.testfw.stf.scripteditor.Activator;
       
    40 import com.nokia.testfw.stf.scripteditor.editors.scripter.ScripterAssistProcessor;
       
    41 import com.nokia.testfw.stf.scripteditor.preference.PreferenceConstants;
       
    42 import com.nokia.testfw.stf.scripteditor.utils.Command;
       
    43 
       
    44 /**
       
    45  * Config source editor configuration
       
    46  * 
       
    47  */
       
    48 
       
    49 public class ScriptEditorConfiguration extends SourceViewerConfiguration {
       
    50 
       
    51 	/**
       
    52 	 * Creates Script Editor configuration
       
    53 	 */
       
    54 	public ScriptEditorConfiguration() {
       
    55 		assistant = new ContentAssistant();
       
    56 		reconciler = new PresentationReconciler();
       
    57 		scriptScanner = new ScriptScanner();
       
    58 		repairer = new DefaultDamagerRepairer(scriptScanner);
       
    59 		scripterAssistProcessor = new ScripterAssistProcessor();
       
    60 		
       
    61 		IPreferenceStore store = Activator.getDefault().getPreferenceStore();
       
    62 		
       
    63 		assistant.enableAutoActivation(store.getBoolean(PreferenceConstants.AUTO_ACTIVATION));
       
    64 		assistant.setAutoActivationDelay(store.getInt(PreferenceConstants.AUTO_ACTIVATION_DELAY));
       
    65 	}
       
    66 
       
    67 	/*
       
    68 	 * (non-Javadoc)
       
    69 	 * 
       
    70 	 * @see org.eclipse.ui.editors.text.TextSourceViewerConfiguration#getAnnotationHover
       
    71 	 */
       
    72 	public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
       
    73 		return new DefaultAnnotationHover();
       
    74 	}
       
    75 
       
    76 	/*
       
    77 	 * (non-Javadoc)
       
    78 	 * 
       
    79 	 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getPresentationReconciler(org.eclipse.jface.text.source.ISourceViewer)
       
    80 	 */
       
    81 	public IPresentationReconciler getPresentationReconciler(ISourceViewer arg0) {
       
    82 		reconciler.setRepairer(repairer, IDocument.DEFAULT_CONTENT_TYPE);
       
    83 		reconciler.setDamager(repairer, IDocument.DEFAULT_CONTENT_TYPE);
       
    84 		return reconciler;
       
    85 	}
       
    86 
       
    87 	/*
       
    88 	 * (non-Javadoc)
       
    89 	 * 
       
    90 	 * @see org.eclipse.jface.text.source.SourceViewerConfiguration#getContentAssistant(org.eclipse.jface.text.source.ISourceViewer)
       
    91 	 */
       
    92 	public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
       
    93 		assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer));
       
    94 		return assistant;
       
    95 	}
       
    96 	
       
    97 	public IContentAssistant getContentAssistant() {
       
    98 		return assistant;
       
    99 	} 
       
   100 
       
   101 	/**
       
   102 	 * Changes Script Editor mode
       
   103 	 */
       
   104 	public void changeConfigurationMode(ArrayList<String> subSectionContent) {
       
   105 		assistant.setContentAssistProcessor(scripterAssistProcessor,
       
   106 				IDocument.DEFAULT_CONTENT_TYPE);
       
   107 		scriptScanner.changeSetOfKeywords(subSectionContent);
       
   108 	}
       
   109 	
       
   110 	public ITextHover getTextHover(ISourceViewer sourceViewer,
       
   111             String contentType)
       
   112 	{
       
   113 	    return new DefaultTextHover(sourceViewer) {
       
   114 	    	
       
   115 	    	public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion)
       
   116 	        {
       
   117 	    		try {
       
   118 					String keyword = textViewer.getDocument().get(
       
   119 							hoverRegion.getOffset(), hoverRegion.getLength());
       
   120 					ArrayList<Command> cmds = scripterAssistProcessor.getCommand();
       
   121 
       
   122 					for (Command cmd : cmds) {
       
   123 						if (keyword.equals(cmd.getCommandName())) {
       
   124 							return cmd.getCommandInfo(); 
       
   125 						}
       
   126 					}
       
   127 					return null;
       
   128 				}
       
   129 	    		catch (Exception e) {
       
   130 	    			return null;
       
   131 	    		}
       
   132 	            
       
   133 	        }
       
   134 	    	
       
   135 	    	
       
   136 	    	
       
   137 	    };
       
   138 	}
       
   139 	
       
   140 	public String[] getDefaultPrefixes(ISourceViewer sourceViewer, String contentType) {
       
   141         return super.getDefaultPrefixes(sourceViewer, contentType);
       
   142     }
       
   143 
       
   144 	private ContentAssistant assistant;
       
   145 
       
   146 	private PresentationReconciler reconciler;
       
   147 
       
   148 	private DefaultDamagerRepairer repairer;
       
   149 
       
   150 	private ScriptScanner scriptScanner;
       
   151 	
       
   152 	private ScripterAssistProcessor scripterAssistProcessor;
       
   153 }