use of org.eclipse.core.runtime.preferences.IScopeContext in project webtools.sourceediting by eclipse.
the class HTMLAttributeValidationQuickFixProcessor method computeQuickAssistProposals.
/*
* @see org.eclipse.jface.text.quickassist.IQuickAssistProcessor#computeQuickAssistProposals(org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext)
*/
public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) {
ISourceViewer viewer = invocationContext.getSourceViewer();
int documentOffset = invocationContext.getOffset();
int length = viewer != null ? viewer.getSelectedRange().y : 0;
IAnnotationModel model = viewer.getAnnotationModel();
if (model == null)
return null;
List proposals = new ArrayList();
if (model instanceof IAnnotationModelExtension2) {
Iterator iter = ((IAnnotationModelExtension2) model).getAnnotationIterator(documentOffset, length, true, true);
while (iter.hasNext()) {
Annotation anno = (Annotation) iter.next();
if (canFix(anno)) {
int offset = -1;
if (anno instanceof TemporaryAnnotation) {
offset = ((TemporaryAnnotation) anno).getPosition().getOffset();
} else if (anno instanceof MarkerAnnotation) {
offset = ((MarkerAnnotation) anno).getMarker().getAttribute(IMarker.CHAR_START, -1);
}
if (offset == -1)
continue;
IDOMNode node = (IDOMNode) ContentAssistUtils.getNodeAt(viewer, offset);
if (!(node instanceof Element))
continue;
Object adapter = (node instanceof IAdaptable ? ((IAdaptable) node).getAdapter(IResource.class) : null);
IProject project = (adapter instanceof IResource ? ((IResource) adapter).getProject() : null);
IScopeContext[] fLookupOrder = new IScopeContext[] { new InstanceScope(), new DefaultScope() };
if (project != null) {
ProjectScope projectScope = new ProjectScope(project);
if (projectScope.getNode(getPreferenceNodeQualifier()).getBoolean(getProjectSettingsKey(), false))
fLookupOrder = new IScopeContext[] { projectScope, new InstanceScope(), new DefaultScope() };
}
boolean ignore = fPreferenceService.getBoolean(getPreferenceNodeQualifier(), HTMLCorePreferenceNames.IGNORE_ATTRIBUTE_NAMES, HTMLCorePreferenceNames.IGNORE_ATTRIBUTE_NAMES_DEFAULT, fLookupOrder);
String ignoreList = fPreferenceService.getString(getPreferenceNodeQualifier(), HTMLCorePreferenceNames.ATTRIBUTE_NAMES_TO_IGNORE, HTMLCorePreferenceNames.ATTRIBUTE_NAMES_TO_IGNORE_DEFAULT, fLookupOrder);
Set result = new HashSet();
if (ignoreList.trim().length() > 0) {
// $NON-NLS-1$
String[] names = ignoreList.split(",");
for (int i = 0; names != null && i < names.length; i++) {
String name = names[i] == null ? null : names[i].trim();
if (name != null && name.length() > 0)
result.add(name.toLowerCase());
}
}
String name = getAttributeName(node, offset);
if (name == null)
continue;
// If ignore == false. then show a quick fix anyway (due to allow to turn 'ignore' option on)
if (!ignore || shouldShowQuickFix(result, name.toLowerCase())) {
IgnoreAttributeNameCompletionProposal p = new IgnoreAttributeNameCompletionProposal(name.toLowerCase(), offset, NLS.bind(HTMLUIMessages.DoNotValidateAttribute, name), HTMLUIMessages.DoNotValidateAttributeAddInfo, node);
if (!proposals.contains(p))
proposals.add(p);
}
int dashIndex = name.indexOf('-');
while (dashIndex != -1) {
StringBuffer namePattern = new StringBuffer(name.substring(0, dashIndex + 1)).append('*');
// a more common pattern is already created
if (ignore && result.contains(namePattern.toString().toLowerCase()))
break;
IgnoreAttributeNameCompletionProposal p = new IgnoreAttributeNameCompletionProposal(namePattern.toString().toLowerCase(), offset, NLS.bind(HTMLUIMessages.DoNotValidateAllAttributes, namePattern.toString()), HTMLUIMessages.DoNotValidateAllAttributesAddInfo, node);
if (!proposals.contains(p))
proposals.add(p);
dashIndex = name.indexOf('-', dashIndex + 1);
}
}
}
}
if (proposals.isEmpty())
return null;
return (ICompletionProposal[]) proposals.toArray(new ICompletionProposal[proposals.size()]);
}
use of org.eclipse.core.runtime.preferences.IScopeContext in project webtools.sourceediting by eclipse.
the class IgnoreElementNameCompletionProposal method apply.
/*
* @see ICompletionProposal#apply(IDocument)
*/
public void apply(IDocument document) {
Object adapter = (fTarget instanceof IAdaptable ? ((IAdaptable) fTarget).getAdapter(IResource.class) : null);
IProject project = (adapter instanceof IResource ? ((IResource) adapter).getProject() : null);
IScopeContext[] fLookupOrder = new IScopeContext[] { new InstanceScope(), new DefaultScope() };
boolean hasProjectSettings = false;
if (project != null) {
ProjectScope projectScope = new ProjectScope(project);
if (projectScope.getNode(getPreferenceNodeQualifier()).getBoolean(getProjectSettingsKey(), false)) {
hasProjectSettings = true;
fLookupOrder = new IScopeContext[] { projectScope, new InstanceScope(), new DefaultScope() };
}
}
boolean originalEnableIgnore = fPreferenceService.getBoolean(getPreferenceNodeQualifier(), HTMLCorePreferenceNames.IGNORE_ELEMENT_NAMES, HTMLCorePreferenceNames.IGNORE_ELEMENT_NAMES_DEFAULT, fLookupOrder);
String originalElementNames = fPreferenceService.getString(getPreferenceNodeQualifier(), HTMLCorePreferenceNames.ELEMENT_NAMES_TO_IGNORE, HTMLCorePreferenceNames.ELEMENT_NAMES_TO_IGNORE_DEFAULT, fLookupOrder);
StringBuffer ignoreList = new StringBuffer(originalElementNames);
if (!containsPattern(originalElementNames, fPattern)) {
if (ignoreList.length() > 0)
ignoreList.append(',');
ignoreList.append(fPattern.toLowerCase());
}
fLookupOrder[0].getNode(getPreferenceNodeQualifier()).putBoolean(HTMLCorePreferenceNames.IGNORE_ELEMENT_NAMES, true);
fLookupOrder[0].getNode(getPreferenceNodeQualifier()).put(HTMLCorePreferenceNames.ELEMENT_NAMES_TO_IGNORE, ignoreList.toString());
PreferenceDialog dialog = hasProjectSettings ? PreferencesUtil.createPropertyDialogOn(getShell(), project, HTMLValidationPreferencePage.PROPERTY_PAGE_ID, null, null) : PreferencesUtil.createPreferenceDialogOn(getShell(), HTMLValidationPreferencePage.PREFERENCE_PAGE_ID, null, null);
int result = Window.CANCEL;
if (dialog != null) {
Object page = dialog.getSelectedPage();
if (page instanceof HTMLValidationPreferencePage) {
((HTMLValidationPreferencePage) page).overrideIgnoredElementsOriginValues(originalEnableIgnore, originalElementNames);
}
result = dialog.open();
}
if (Window.CANCEL == result) {
fLookupOrder[0].getNode(getPreferenceNodeQualifier()).putBoolean(HTMLCorePreferenceNames.IGNORE_ELEMENT_NAMES, originalEnableIgnore);
fLookupOrder[0].getNode(getPreferenceNodeQualifier()).put(HTMLCorePreferenceNames.ELEMENT_NAMES_TO_IGNORE, originalElementNames);
for (int i = 0; i < fLookupOrder.length; i++) {
try {
fLookupOrder[i].getNode(getPreferenceNodeQualifier()).flush();
} catch (BackingStoreException e) {
Logger.logException(e);
}
}
}
}
use of org.eclipse.core.runtime.preferences.IScopeContext in project webtools.sourceediting by eclipse.
the class AbstractDocumentLoader method getPlatformLineDelimiterPreference.
/**
* Returns the default line delimiter preference for the given file.
*
* @param file
* the file
* @return the default line delimiter
* @since 3.1
*/
private String getPlatformLineDelimiterPreference(IFile file) {
IScopeContext[] scopeContext;
if (file != null && file.getProject() != null) {
// project preference
scopeContext = new IScopeContext[] { new ProjectScope(file.getProject()) };
String lineDelimiter = Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, null, scopeContext);
if (lineDelimiter != null)
return lineDelimiter;
}
// workspace preference
scopeContext = new IScopeContext[] { new InstanceScope() };
return Platform.getPreferencesService().getString(Platform.PI_RUNTIME, Platform.PREF_LINE_SEPARATOR, null, scopeContext);
}
use of org.eclipse.core.runtime.preferences.IScopeContext in project webtools.sourceediting by eclipse.
the class JSPELTranslator method getScopeContexts.
private IScopeContext[] getScopeContexts(IStructuredDocument document) {
IScopeContext[] scopes = new IScopeContext[] { new InstanceScope(), new DefaultScope() };
final IFile file = getFile(document);
if (file != null && file.exists()) {
final IProject project = file.getProject();
if (project.exists()) {
ProjectScope projectScope = new ProjectScope(project);
if (projectScope.getNode(PREFERENCE_NODE_QUALIFIER).getBoolean(JSPCorePreferenceNames.VALIDATION_USE_PROJECT_SETTINGS, false)) {
scopes = new IScopeContext[] { projectScope, new InstanceScope(), new DefaultScope() };
}
}
}
return scopes;
}
use of org.eclipse.core.runtime.preferences.IScopeContext in project webtools.sourceediting by eclipse.
the class JSONValidatorPreferencePage method createContentsForSyntaxValidationGroup.
protected void createContentsForSyntaxValidationGroup(Composite parent) {
IScopeContext[] contexts = createPreferenceScopes();
fOriginalUseExtendedSyntaxValidation = getBooleanPreference(JSONCorePreferenceNames.SYNTAX_VALIDATION, false, contexts);
fExtendedSyntaxValidation = createCheckBox(parent, JSONUIMessages.SyntaxValidation_files);
((GridData) fExtendedSyntaxValidation.getLayoutData()).horizontalSpan = 2;
fExtendedSyntaxValidation.setSelection(fOriginalUseExtendedSyntaxValidation);
fExtendedSyntaxValidation.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
handleSyntaxSeveritySelection(fExtendedSyntaxValidation.getSelection());
}
});
fOriginalUseSchemaValidation = getBooleanPreference(JSONCorePreferenceNames.SCHEMA_VALIDATION, false, contexts);
fSchemaValidation = createCheckBox(parent, JSONUIMessages.EnableSchemaValidation);
((GridData) fSchemaValidation.getLayoutData()).horizontalSpan = 2;
fSchemaValidation.setSelection(fOriginalUseSchemaValidation);
fSyntaxValidationGroup = createGroup(parent, 3);
((GridLayout) fSyntaxValidationGroup.getLayout()).makeColumnsEqualWidth = false;
fSyntaxValidationGroup.setText(JSONUIMessages.SyntaxValidation_files_label);
GridLayout layout = new GridLayout(3, false);
fSyntaxValidationGroup.setLayout(layout);
if (fMissingStartTag == null) {
fMissingStartTag = addComboBox(fSyntaxValidationGroup, JSONUIMessages.Missing_start_object, JSONCorePreferenceNames.MISSING_START_OBJECT, JSON_SEVERITIES, SYNTAX_SEVERITIES, 0);
}
if (fMissingEndTag == null) {
fMissingEndTag = addComboBox(fSyntaxValidationGroup, JSONUIMessages.Missing_end_object, JSONCorePreferenceNames.MISSING_END_OBJECT, JSON_SEVERITIES, SYNTAX_SEVERITIES, 0);
}
// if (fMissingEndTag == null)
// fMissingEndTag = addComboBox(fSyntaxValidationGroup,
// JSONUIMessages.Missing_end_tag,
// JSONCorePreferenceNames.MISSING_END_TAG, JSON_SEVERITIES,
// SYNTAX_SEVERITIES, 0);
// if (fMissingTagName == null)
// fMissingTagName = addComboBox(fSyntaxValidationGroup,
// JSONUIMessages.Tag_name_missing,
// JSONCorePreferenceNames.MISSING_TAG_NAME, JSON_SEVERITIES,
// SYNTAX_SEVERITIES, 0);
// if (fMissingQuotes == null)
// fMissingQuotes = addComboBox(fSyntaxValidationGroup,
// JSONUIMessages.Missing_quotes,
// JSONCorePreferenceNames.MISSING_QUOTES, JSON_SEVERITIES,
// SYNTAX_SEVERITIES, 0);
// if (fMissingClosingBracket == null)
// fMissingClosingBracket = addComboBox(fSyntaxValidationGroup,
// JSONUIMessages.Missing_closing_bracket,
// JSONCorePreferenceNames.MISSING_CLOSING_BRACKET,
// JSON_SEVERITIES, SYNTAX_SEVERITIES, 0);
// if (fMissingClosingQuote == null)
// fMissingClosingQuote = addComboBox(fSyntaxValidationGroup,
// JSONUIMessages.Missing_closing_quote,
// JSONCorePreferenceNames.MISSING_CLOSING_QUOTE,
// JSON_SEVERITIES, SYNTAX_SEVERITIES, 0);
// if (fEmptyElementTag == null)
// fEmptyElementTag = addComboBox(fSyntaxValidationGroup,
// JSONUIMessages.Empty_element_tag,
// JSONCorePreferenceNames.ATTRIBUTE_HAS_NO_VALUE,
// JSON_SEVERITIES, SYNTAX_SEVERITIES, 0);
// if (fEndTagWithAttributes == null)
// fEndTagWithAttributes = addComboBox(fSyntaxValidationGroup,
// JSONUIMessages.End_tag_with_attributes,
// JSONCorePreferenceNames.END_TAG_WITH_ATTRIBUTES,
// JSON_SEVERITIES, SYNTAX_SEVERITIES, 0);
// if (fInvalidWhitespaceBeforeTagname == null)
// fInvalidWhitespaceBeforeTagname = addComboBox(
// fSyntaxValidationGroup,
// JSONUIMessages.Invalid_whitespace_before_tagname,
// JSONCorePreferenceNames.WHITESPACE_BEFORE_TAGNAME,
// JSON_SEVERITIES, SYNTAX_SEVERITIES, 0);
// if (fInvalidNamespaceInPI == null)
// fInvalidNamespaceInPI = addComboBox(fSyntaxValidationGroup,
// JSONUIMessages.Namespace_in_pi_target,
// JSONCorePreferenceNames.NAMESPACE_IN_PI_TARGET,
// JSON_SEVERITIES, SYNTAX_SEVERITIES, 0);
// if (fInvalidWhitespaceAtStart == null)
// fInvalidWhitespaceAtStart = addComboBox(fSyntaxValidationGroup,
// JSONUIMessages.Whitespace_at_start,
// JSONCorePreferenceNames.WHITESPACE_AT_START,
// JSON_SEVERITIES, SYNTAX_SEVERITIES, 0);
handleSyntaxSeveritySelection(fOriginalUseExtendedSyntaxValidation);
}
Aggregations