Search in sources :

Example 46 with IScopeContext

use of org.eclipse.core.runtime.preferences.IScopeContext 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);
            }
        }
    }
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) IAdaptable(org.eclipse.core.runtime.IAdaptable) BackingStoreException(org.osgi.service.prefs.BackingStoreException) DefaultScope(org.eclipse.core.runtime.preferences.DefaultScope) IProject(org.eclipse.core.resources.IProject) Point(org.eclipse.swt.graphics.Point) HTMLValidationPreferencePage(org.eclipse.wst.html.ui.internal.preferences.ui.HTMLValidationPreferencePage) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) PreferenceDialog(org.eclipse.jface.preference.PreferenceDialog) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) IResource(org.eclipse.core.resources.IResource)

Example 47 with IScopeContext

use of org.eclipse.core.runtime.preferences.IScopeContext 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()]);
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) IAdaptable(org.eclipse.core.runtime.IAdaptable) HashSet(java.util.HashSet) Set(java.util.Set) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) IAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) IDOMNode(org.eclipse.wst.xml.core.internal.provisional.document.IDOMNode) ICompletionProposal(org.eclipse.jface.text.contentassist.ICompletionProposal) Iterator(java.util.Iterator) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) ArrayList(java.util.ArrayList) List(java.util.List) HashSet(java.util.HashSet) DefaultScope(org.eclipse.core.runtime.preferences.DefaultScope) Annotation(org.eclipse.jface.text.source.Annotation) MarkerAnnotation(org.eclipse.ui.texteditor.MarkerAnnotation) TemporaryAnnotation(org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation) IProject(org.eclipse.core.resources.IProject) IAnnotationModelExtension2(org.eclipse.jface.text.source.IAnnotationModelExtension2) MarkerAnnotation(org.eclipse.ui.texteditor.MarkerAnnotation) ISourceViewer(org.eclipse.jface.text.source.ISourceViewer) TemporaryAnnotation(org.eclipse.wst.sse.ui.internal.reconcile.TemporaryAnnotation) IResource(org.eclipse.core.resources.IResource)

Example 48 with IScopeContext

use of org.eclipse.core.runtime.preferences.IScopeContext in project webtools.sourceediting by eclipse.

the class AbstractValidationSettingsPage method storeValues.

/*
	 * (non-Javadoc)
	 * @see org.eclipse.wst.sse.ui.internal.preferences.ui.AbstractSettingsPage#storeValues()
	 */
protected void storeValues() {
    if (fCombos == null || fCombos.size() == 0)
        return;
    Iterator it = fCombos.iterator();
    IScopeContext[] contexts = createPreferenceScopes();
    while (it.hasNext()) {
        ComboData data = (ComboData) ((Combo) it.next()).getData();
        if (data.getKey() != null) {
            contexts[0].getNode(getPreferenceNodeQualifier()).putInt(data.getKey(), data.getSeverity());
            data.originalSeverity = data.getSeverity();
        }
    }
    for (int i = 0; i < contexts.length; i++) {
        try {
            contexts[i].getNode(getPreferenceNodeQualifier()).flush();
        } catch (BackingStoreException e) {
        }
    }
}
Also used : IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) Iterator(java.util.Iterator) BackingStoreException(org.osgi.service.prefs.BackingStoreException)

Example 49 with IScopeContext

use of org.eclipse.core.runtime.preferences.IScopeContext in project webtools.sourceediting by eclipse.

the class ELGeneratorVisitor method getScopeContexts.

private IScopeContext[] getScopeContexts() {
    IScopeContext[] scopes = new IScopeContext[] { new InstanceScope(), new DefaultScope() };
    final IFile file = getFile();
    if (file != null && file.exists()) {
        final IProject project = file.getProject();
        if (project.exists()) {
            final 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;
}
Also used : ProjectScope(org.eclipse.core.resources.ProjectScope) IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) IFile(org.eclipse.core.resources.IFile) InstanceScope(org.eclipse.core.runtime.preferences.InstanceScope) DefaultScope(org.eclipse.core.runtime.preferences.DefaultScope) IProject(org.eclipse.core.resources.IProject)

Example 50 with IScopeContext

use of org.eclipse.core.runtime.preferences.IScopeContext in project webtools.sourceediting by eclipse.

the class XMLValidatorPreferencePage method createContentsForMarkupValidationGroup.

protected void createContentsForMarkupValidationGroup(Composite parent) {
    IScopeContext[] contexts = createPreferenceScopes();
    fOriginalUseExtendedMarkupValidation = getBooleanPreference(XMLCorePreferenceNames.MARKUP_VALIDATION, false, contexts);
    fExtendedMarkupValidation = createCheckBox(parent, XMLUIMessages.MarkupValidation_files);
    ((GridData) fExtendedMarkupValidation.getLayoutData()).horizontalSpan = 2;
    fExtendedMarkupValidation.setSelection(fOriginalUseExtendedMarkupValidation);
    fExtendedMarkupValidation.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            handleMarkupSeveritySelection(fExtendedMarkupValidation.getSelection());
        }
    });
    fMarkupValidationGroup = createGroup(parent, 3);
    ((GridLayout) fMarkupValidationGroup.getLayout()).makeColumnsEqualWidth = false;
    fMarkupValidationGroup.setText(XMLUIMessages.MarkupValidation_files_label);
    GridLayout layout = new GridLayout(3, false);
    fMarkupValidationGroup.setLayout(layout);
    if (fMissingStartTag == null)
        fMissingStartTag = addComboBox(fMarkupValidationGroup, XMLUIMessages.Missing_start_tag, XMLCorePreferenceNames.MISSING_START_TAG, XML_SEVERITIES, MARKUP_SEVERITIES, 0);
    if (fMissingEndTag == null)
        fMissingEndTag = addComboBox(fMarkupValidationGroup, XMLUIMessages.Missing_end_tag, XMLCorePreferenceNames.MISSING_END_TAG, XML_SEVERITIES, MARKUP_SEVERITIES, 0);
    if (fMissingTagName == null)
        fMissingTagName = addComboBox(fMarkupValidationGroup, XMLUIMessages.Tag_name_missing, XMLCorePreferenceNames.MISSING_TAG_NAME, XML_SEVERITIES, MARKUP_SEVERITIES, 0);
    if (fMissingQuotes == null)
        fMissingQuotes = addComboBox(fMarkupValidationGroup, XMLUIMessages.Missing_quotes, XMLCorePreferenceNames.MISSING_QUOTES, XML_SEVERITIES, MARKUP_SEVERITIES, 0);
    if (fMissingClosingBracket == null)
        fMissingClosingBracket = addComboBox(fMarkupValidationGroup, XMLUIMessages.Missing_closing_bracket, XMLCorePreferenceNames.MISSING_CLOSING_BRACKET, XML_SEVERITIES, MARKUP_SEVERITIES, 0);
    if (fMissingClosingQuote == null)
        fMissingClosingQuote = addComboBox(fMarkupValidationGroup, XMLUIMessages.Missing_closing_quote, XMLCorePreferenceNames.MISSING_CLOSING_QUOTE, XML_SEVERITIES, MARKUP_SEVERITIES, 0);
    if (fEmptyElementTag == null)
        fEmptyElementTag = addComboBox(fMarkupValidationGroup, XMLUIMessages.Empty_element_tag, XMLCorePreferenceNames.ATTRIBUTE_HAS_NO_VALUE, XML_SEVERITIES, MARKUP_SEVERITIES, 0);
    if (fEndTagWithAttributes == null)
        fEndTagWithAttributes = addComboBox(fMarkupValidationGroup, XMLUIMessages.End_tag_with_attributes, XMLCorePreferenceNames.END_TAG_WITH_ATTRIBUTES, XML_SEVERITIES, MARKUP_SEVERITIES, 0);
    if (fInvalidWhitespaceBeforeTagname == null)
        fInvalidWhitespaceBeforeTagname = addComboBox(fMarkupValidationGroup, XMLUIMessages.Invalid_whitespace_before_tagname, XMLCorePreferenceNames.WHITESPACE_BEFORE_TAGNAME, XML_SEVERITIES, MARKUP_SEVERITIES, 0);
    if (fInvalidNamespaceInPI == null)
        fInvalidNamespaceInPI = addComboBox(fMarkupValidationGroup, XMLUIMessages.Namespace_in_pi_target, XMLCorePreferenceNames.NAMESPACE_IN_PI_TARGET, XML_SEVERITIES, MARKUP_SEVERITIES, 0);
    if (fInvalidWhitespaceAtStart == null)
        fInvalidWhitespaceAtStart = addComboBox(fMarkupValidationGroup, XMLUIMessages.Whitespace_at_start, XMLCorePreferenceNames.WHITESPACE_AT_START, XML_SEVERITIES, MARKUP_SEVERITIES, 0);
    handleMarkupSeveritySelection(fOriginalUseExtendedMarkupValidation);
}
Also used : IScopeContext(org.eclipse.core.runtime.preferences.IScopeContext) GridLayout(org.eclipse.swt.layout.GridLayout) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Aggregations

IScopeContext (org.eclipse.core.runtime.preferences.IScopeContext)74 ProjectScope (org.eclipse.core.resources.ProjectScope)42 IEclipsePreferences (org.eclipse.core.runtime.preferences.IEclipsePreferences)17 InstanceScope (org.eclipse.core.runtime.preferences.InstanceScope)16 DefaultScope (org.eclipse.core.runtime.preferences.DefaultScope)15 BackingStoreException (org.osgi.service.prefs.BackingStoreException)15 Preferences (org.osgi.service.prefs.Preferences)14 IProject (org.eclipse.core.resources.IProject)13 CoreException (org.eclipse.core.runtime.CoreException)8 ArrayList (java.util.ArrayList)6 IResource (org.eclipse.core.resources.IResource)6 ILiferayProjectProvider (com.liferay.ide.core.ILiferayProjectProvider)5 Iterator (java.util.Iterator)5 HashSet (java.util.HashSet)4 List (java.util.List)4 Set (java.util.Set)4 IFile (org.eclipse.core.resources.IFile)4 IAdaptable (org.eclipse.core.runtime.IAdaptable)4 PreferencesAccess (org.eclipse.jdt.internal.ui.preferences.PreferencesAccess)4 FormatterProfileStore (org.eclipse.jdt.internal.ui.preferences.formatter.FormatterProfileStore)4