use of org.eclipse.core.runtime.preferences.DefaultScope in project webtools.sourceediting by eclipse.
the class HTMLValidationPreferencePage method resetIgnoreNamesPatterns.
protected void resetIgnoreNamesPatterns() {
IEclipsePreferences defaultContext = new DefaultScope().getNode(getPreferenceNodeQualifier());
BooleanData ignoreData = (BooleanData) fIgnoreElementNames.getData();
boolean ignoreElementNames = defaultContext.getBoolean(ignoreData.getKey(), HTMLCorePreferenceNames.IGNORE_ELEMENT_NAMES_DEFAULT);
ignoreData.setValue(ignoreElementNames);
fIgnoreElementNames.setSelection(ignoreData.getValue());
TextData data = (TextData) fIgnoredElementNames.getData();
String ignoredElementNames = defaultContext.get(data.getKey(), HTMLCorePreferenceNames.ELEMENT_NAMES_TO_IGNORE_DEFAULT);
data.setValue(ignoredElementNames);
fIgnoredElementNames.setText(data.getValue());
ignoreData = (BooleanData) fIgnoreAttributeNames.getData();
boolean ignoreAttributeNames = defaultContext.getBoolean(ignoreData.getKey(), HTMLCorePreferenceNames.IGNORE_ATTRIBUTE_NAMES_DEFAULT);
ignoreData.setValue(ignoreAttributeNames);
fIgnoreAttributeNames.setSelection(ignoreData.getValue());
data = (TextData) fIgnoredAttributeNames.getData();
String ignoredAttributeNames = defaultContext.get(data.getKey(), HTMLCorePreferenceNames.ATTRIBUTE_NAMES_TO_IGNORE_DEFAULT);
data.setValue(ignoredAttributeNames);
fIgnoredAttributeNames.setText(data.getValue());
controlChanged(fIgnoreAttributeNames);
}
use of org.eclipse.core.runtime.preferences.DefaultScope in project webtools.sourceediting by eclipse.
the class MessageFactory method init.
private void init() {
fPreferenceService = Platform.getPreferencesService();
fLookupOrder = new IScopeContext[] { new InstanceScope(), new DefaultScope() };
if (fProject != null) {
ProjectScope projectScope = new ProjectScope(fProject);
if (projectScope.getNode(HTMLCorePlugin.getDefault().getBundle().getSymbolicName()).getBoolean(HTMLCorePreferenceNames.USE_PROJECT_SETTINGS, false))
fLookupOrder = new IScopeContext[] { projectScope, new InstanceScope(), new DefaultScope() };
}
for (int i = 0; i < NodeType.MAX_TYPE; i++) {
errTables[i] = new ErrorTable();
}
// NOTE: The severities are just stub. They must be reviewed.
// -- 8/30/2001
// attribute error map
// short hand
ErrorTable attrTable = errTables[NodeType.ATTRIBUTE];
attrTable.put(NONE_ERROR, MSG_NO_ERROR, 0);
mapToKey(HTMLCorePreferenceNames.ATTRIBUTE_UNDEFINED_NAME, attrTable, UNDEFINED_NAME_ERROR, MSG_UNDEFINED_ATTR_ERROR);
mapToKey(HTMLCorePreferenceNames.ATTRIBUTE_UNDEFINED_VALUE, attrTable, UNDEFINED_VALUE_ERROR, MSG_UNDEFINED_VALUE_ERROR);
mapToKey(HTMLCorePreferenceNames.ATTRIBUTE_NAME_MISMATCH, attrTable, MISMATCHED_ERROR, MSG_MISMATCHED_ATTR_ERROR);
mapToKey(HTMLCorePreferenceNames.ATTRIBUTE_INVALID_NAME, attrTable, INVALID_NAME_ERROR, MSG_INVALID_ATTR_ERROR);
mapToKey(HTMLCorePreferenceNames.ATTRIBUTE_INVALID_VALUE, attrTable, INVALID_ATTR_ERROR, MSG_ATTR_NO_VALUE_ERROR);
mapToKey(HTMLCorePreferenceNames.ATTRIBUTE_DUPLICATE, attrTable, DUPLICATE_ERROR, MSG_DUPLICATE_ATTR_ERROR);
mapToKey(HTMLCorePreferenceNames.ATTRIBUTE_VALUE_MISMATCH, attrTable, MISMATCHED_VALUE_ERROR, MSG_MISMATCHED_ATTR_VALUE_ERROR);
mapToKey(HTMLCorePreferenceNames.ATTRIBUTE_VALUE_UNCLOSED, attrTable, UNCLOSED_ATTR_VALUE, MSG_UNCLOSED_ATTR_VALUE_ERROR);
mapToKey(HTMLCorePreferenceNames.ATTRIBUTE_VALUE_RESOURCE_NOT_FOUND, attrTable, RESOURCE_NOT_FOUND, MSG_RESOURCE_NOT_FOUND);
mapToKey(HTMLCorePreferenceNames.ATTRIBUTE_OBSOLETE_NAME, attrTable, OBSOLETE_ATTR_NAME_ERROR, MSG_OBSOLETE_ATTR_ERROR);
mapToKey(HTMLCorePreferenceNames.ATTRIBUTE_VALUE_EQUALS_MISSING, attrTable, MISSING_ATTR_VALUE_EQUALS_ERROR, MSG_MISSING_ATTR_VALUE_EQUALS_ERROR);
// element error map
// short hand
ErrorTable elemTable = errTables[NodeType.ELEMENT];
elemTable.put(NONE_ERROR, MSG_NO_ERROR, 0);
mapToKey(HTMLCorePreferenceNames.ELEM_UNKNOWN_NAME, elemTable, UNDEFINED_NAME_ERROR, MSG_UNDEFINED_TAG_ERROR);
mapToKey(HTMLCorePreferenceNames.ELEM_INVALID_NAME, elemTable, INVALID_NAME_ERROR, MSG_INVALID_TAG_ERROR);
mapToKey(HTMLCorePreferenceNames.ELEM_START_INVALID_CASE, elemTable, MISMATCHED_ERROR, MSG_MISMATCHED_TAG_ERROR);
mapToKey(HTMLCorePreferenceNames.ELEM_END_INVALID_CASE, elemTable, MISMATCHED_END_TAG_ERROR, MSG_MISMATCHED_TAG_ERROR);
mapToKey(HTMLCorePreferenceNames.ELEM_MISSING_START, elemTable, MISSING_START_TAG_ERROR, MSG_MISSING_START_TAG_ERROR);
mapToKey(HTMLCorePreferenceNames.ELEM_MISSING_END, elemTable, MISSING_END_TAG_ERROR, MSG_MISSING_END_TAG_ERROR);
mapToKey(HTMLCorePreferenceNames.ELEM_UNNECESSARY_END, elemTable, UNNECESSARY_END_TAG_ERROR, MSG_UNNECESSARY_END_TAG_ERROR);
mapToKey(HTMLCorePreferenceNames.ELEM_INVALID_DIRECTIVE, elemTable, INVALID_DIRECTIVE_ERROR, MSG_INVALID_DIRECTIVE_ERROR);
mapToKey(HTMLCorePreferenceNames.ELEM_INVALID_CONTENT, elemTable, INVALID_CONTENT_ERROR, MSG_INVALID_CONTENT_ERROR);
mapToKey(HTMLCorePreferenceNames.ELEM_DUPLICATE, elemTable, DUPLICATE_ERROR, MSG_DUPLICATE_TAG_ERROR);
mapToKey(HTMLCorePreferenceNames.ELEM_COEXISTENCE, elemTable, COEXISTENCE_ERROR, MSG_INVALID_CONTENT_ERROR);
mapToKey(HTMLCorePreferenceNames.ELEM_UNCLOSED_START_TAG, elemTable, UNCLOSED_TAG_ERROR, MSG_UNCLOSED_START_TAG_ERROR);
mapToKey(HTMLCorePreferenceNames.ELEM_UNCLOSED_END_TAG, elemTable, UNCLOSED_END_TAG_ERROR, MSG_UNCLOSED_END_TAG_ERROR);
mapToKey(HTMLCorePreferenceNames.ELEM_INVALID_EMPTY_TAG, elemTable, INVALID_EMPTY_ELEMENT_TAG, MSG_INVALID_EMPTY_ELEMENT_TAG);
mapToKey(HTMLCorePreferenceNames.ELEM_OBSOLETE_NAME, elemTable, OBSOLETE_TAG_NAME_ERROR, MSG_OBSOLETE_TAG_ERROR);
mapToKey(HTMLCorePreferenceNames.ELEM_INVALID_TEXT, elemTable, INVALID_TEXT_IN_ELEM_ERROR, MSG_INVALID_TEXT_IN_ELEM_ERROR);
// document type error map
// short hand
ErrorTable docTable = errTables[NodeType.DOCUMENT_TYPE];
docTable.put(NONE_ERROR, MSG_NO_ERROR, 0);
mapToKey(HTMLCorePreferenceNames.DOC_DUPLICATE, docTable, DUPLICATE_ERROR, MSG_DUPLICATE_TAG_ERROR);
mapToKey(HTMLCorePreferenceNames.DOC_INVALID_CONTENT, docTable, INVALID_CONTENT_ERROR, MSG_INVALID_CONTENT_ERROR);
mapToKey(HTMLCorePreferenceNames.DOC_DOCTYPE_UNCLOSED, docTable, UNCLOSED_TAG_ERROR, MSG_UNCLOSED_DOCTYPE_ERROR);
// text error map
ErrorTable textTable = errTables[NodeType.TEXT];
textTable.put(NONE_ERROR, MSG_NO_ERROR, 0);
mapToKey(HTMLCorePreferenceNames.TEXT_INVALID_CONTENT, textTable, INVALID_CONTENT_ERROR, MSG_INVALID_TEXT_ERROR);
mapToKey(HTMLCorePreferenceNames.TEXT_INVALID_CHAR, textTable, INVALID_CHAR_ERROR, MSG_INVALID_CHAR_ERROR);
// comment error map
ErrorTable commTable = errTables[NodeType.COMMENT];
commTable.put(NONE_ERROR, MSG_NO_ERROR, 0);
mapToKey(HTMLCorePreferenceNames.COMMENT_INVALID_CONTENT, commTable, INVALID_CONTENT_ERROR, MSG_INVALID_CONTENT_ERROR);
mapToKey(HTMLCorePreferenceNames.COMMENT_UNCLOSED, commTable, UNCLOSED_TAG_ERROR, MSG_UNCLOSED_COMMENT_ERROR);
// cdata section error map
ErrorTable cdatTable = errTables[NodeType.CDATA_SECTION];
cdatTable.put(NONE_ERROR, MSG_NO_ERROR, 0);
mapToKey(HTMLCorePreferenceNames.CDATA_INVALID_CONTENT, cdatTable, INVALID_CONTENT_ERROR, MSG_INVALID_CONTENT_ERROR);
mapToKey(HTMLCorePreferenceNames.CDATA_UNCLOSED, cdatTable, UNCLOSED_TAG_ERROR, MSG_UNCLOSED_CDATA_SECTION_ERROR);
// processing instruction error map
ErrorTable piTable = errTables[NodeType.PROCESSING_INSTRUCTION];
piTable.put(NONE_ERROR, MSG_NO_ERROR, 0);
mapToKey(HTMLCorePreferenceNames.PI_INVALID_CONTENT, piTable, INVALID_CONTENT_ERROR, MSG_INVALID_CONTENT_ERROR);
mapToKey(HTMLCorePreferenceNames.PI_UNCLOSED, piTable, UNCLOSED_TAG_ERROR, MSG_UNCLOSED_PI_ERROR);
// entity reference error map
ErrorTable erTable = errTables[NodeType.ENTITY_REFERENCE];
erTable.put(NONE_ERROR, MSG_NO_ERROR, 0);
mapToKey(HTMLCorePreferenceNames.REF_UNDEFINED, erTable, UNDEFINED_NAME_ERROR, MSG_UNDEFINED_TAG_ERROR);
mapToKey(HTMLCorePreferenceNames.REF_INVALID_CONTENT, erTable, INVALID_CONTENT_ERROR, MSG_INVALID_CONTENT_ERROR);
}
use of org.eclipse.core.runtime.preferences.DefaultScope in project webtools.sourceediting by eclipse.
the class IgnoreAttributeNameCompletionProposal 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_ATTRIBUTE_NAMES, HTMLCorePreferenceNames.IGNORE_ATTRIBUTE_NAMES_DEFAULT, fLookupOrder);
String originalAttributeNames = fPreferenceService.getString(getPreferenceNodeQualifier(), HTMLCorePreferenceNames.ATTRIBUTE_NAMES_TO_IGNORE, HTMLCorePreferenceNames.ATTRIBUTE_NAMES_TO_IGNORE_DEFAULT, fLookupOrder);
StringBuffer ignoreList = new StringBuffer(originalAttributeNames);
if (!containsPattern(originalAttributeNames, fPattern)) {
if (ignoreList.length() > 0)
ignoreList.append(',');
ignoreList.append(fPattern.toLowerCase());
}
fLookupOrder[0].getNode(getPreferenceNodeQualifier()).putBoolean(HTMLCorePreferenceNames.IGNORE_ATTRIBUTE_NAMES, true);
fLookupOrder[0].getNode(getPreferenceNodeQualifier()).put(HTMLCorePreferenceNames.ATTRIBUTE_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).overrideIgnoredAttributesOriginValues(originalEnableIgnore, originalAttributeNames);
}
result = dialog.open();
}
if (Window.CANCEL == result) {
fLookupOrder[0].getNode(getPreferenceNodeQualifier()).putBoolean(HTMLCorePreferenceNames.IGNORE_ATTRIBUTE_NAMES, originalEnableIgnore);
fLookupOrder[0].getNode(getPreferenceNodeQualifier()).put(HTMLCorePreferenceNames.ATTRIBUTE_NAMES_TO_IGNORE, originalAttributeNames);
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.DefaultScope in project webtools.sourceediting by eclipse.
the class HTMLSyntaxValidationQuickFixProcessor 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_ELEMENT_NAMES, HTMLCorePreferenceNames.IGNORE_ELEMENT_NAMES_DEFAULT, fLookupOrder);
String ignoreList = fPreferenceService.getString(getPreferenceNodeQualifier(), HTMLCorePreferenceNames.ELEMENT_NAMES_TO_IGNORE, HTMLCorePreferenceNames.ELEMENT_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 = getElementName(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())) {
IgnoreElementNameCompletionProposal p = new IgnoreElementNameCompletionProposal(name.toLowerCase(), offset, NLS.bind(HTMLUIMessages.DoNotValidateElement, name), HTMLUIMessages.DoNotValidateElementAddInfo, 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;
IgnoreElementNameCompletionProposal p = new IgnoreElementNameCompletionProposal(namePattern.toString().toLowerCase(), offset, NLS.bind(HTMLUIMessages.DoNotValidateAllElements, namePattern.toString()), HTMLUIMessages.DoNotValidateAllElementsAddInfo, 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.DefaultScope in project webtools.sourceediting by eclipse.
the class AbstractValidationSettingsPage method resetSeverities.
protected void resetSeverities() {
IEclipsePreferences defaultContext = new DefaultScope().getNode(getPreferenceNodeQualifier());
for (int i = 0; i < fCombos.size(); i++) {
ComboData data = (ComboData) ((Combo) fCombos.get(i)).getData();
int severity = defaultContext.getInt(data.getKey(), ValidationMessage.WARNING);
data.setSeverity(severity);
((Combo) fCombos.get(i)).select(data.getIndex());
}
}
Aggregations