|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2010 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.wst.jsdt.web.ui.contentassist; |
| 12 |
|
| 13 |
import org.eclipse.jface.preference.IPreferenceStore; |
| 14 |
import org.eclipse.jface.text.ITextViewer; |
| 15 |
import org.eclipse.jface.text.contentassist.ContentAssistant; |
| 16 |
import org.eclipse.jface.util.PropertyChangeEvent; |
| 17 |
import org.eclipse.wst.jsdt.ui.PreferenceConstants; |
| 18 |
import org.eclipse.wst.sse.ui.contentassist.StructuredContentAssistProcessor; |
| 19 |
|
| 20 |
/** |
| 21 |
* <p>Content assist processor for Javascript regions so that autoactivation will work in those regions.</p> |
| 22 |
* |
| 23 |
* <p><b>NOTE:</b> This class does not check that the given partition type is a javascript region, it just |
| 24 |
* assumes it is, so the instantiator of this class must be sure they want the given partition type to be |
| 25 |
* treated as if it was Javascript.</p> |
| 26 |
*/ |
| 27 |
public class JSDTStructuredContentAssistProcessor extends StructuredContentAssistProcessor { |
| 28 |
/** auto activation characters */ |
| 29 |
private char[] fCompletionPropoaslAutoActivationCharacters; |
| 30 |
|
| 31 |
/** |
| 32 |
* @param assistant {@link ContentAssistant} to use |
| 33 |
* @param partitionTypeID the Javascript partition type this processor is for |
| 34 |
* @param viewer {@link ITextViewer} this processor is acting in |
| 35 |
*/ |
| 36 |
public JSDTStructuredContentAssistProcessor(ContentAssistant assistant, |
| 37 |
String partitionTypeID, ITextViewer viewer) { |
| 38 |
super(assistant, partitionTypeID, viewer, PreferenceConstants.getPreferenceStore()); |
| 39 |
|
| 40 |
//get the current user preference |
| 41 |
getAutoActivationCharacterPreferences(); |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* @see org.eclipse.wst.sse.ui.contentassist.StructuredContentAssistProcessor#getCompletionProposalAutoActivationCharacters() |
| 46 |
*/ |
| 47 |
public char[] getCompletionProposalAutoActivationCharacters() { |
| 48 |
return this.fCompletionPropoaslAutoActivationCharacters; |
| 49 |
} |
| 50 |
|
| 51 |
/** |
| 52 |
* @see org.eclipse.wst.sse.ui.contentassist.StructuredContentAssistProcessor#propertyChange( |
| 53 |
* org.eclipse.jface.util.PropertyChangeEvent) |
| 54 |
*/ |
| 55 |
public void propertyChange(PropertyChangeEvent event) { |
| 56 |
String property = event.getProperty(); |
| 57 |
if(property.equals(PreferenceConstants.CODEASSIST_AUTOACTIVATION) || |
| 58 |
property.equals(PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVA)) { |
| 59 |
|
| 60 |
getAutoActivationCharacterPreferences(); |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* <p>Gets the auto activation character user preferences for Javascript and stores them for later use</p> |
| 66 |
*/ |
| 67 |
private void getAutoActivationCharacterPreferences() { |
| 68 |
IPreferenceStore store = getPreferenceStore(); |
| 69 |
|
| 70 |
boolean doAuto = store.getBoolean(PreferenceConstants.CODEASSIST_AUTOACTIVATION); |
| 71 |
if (doAuto) { |
| 72 |
fCompletionPropoaslAutoActivationCharacters = |
| 73 |
store.getString(PreferenceConstants.CODEASSIST_AUTOACTIVATION_TRIGGERS_JAVA).toCharArray(); |
| 74 |
} else { |
| 75 |
fCompletionPropoaslAutoActivationCharacters = null; |
| 76 |
} |
| 77 |
} |
| 78 |
} |