Skip to main content

This CGIT instance is deprecated, and repositories have been moved to Gitlab or Github. See the repository descriptions for specific locations.

summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentassist')
-rw-r--r--bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentassist/CompoundContentAssistProcessor.java422
-rw-r--r--bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentassist/ContentAssistUtils.java92
-rw-r--r--bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentassist/CustomCompletionProposal.java333
-rw-r--r--bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentassist/IRelevanceCompletionProposal.java28
-rw-r--r--bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentassist/IRelevanceConstants.java17
-rw-r--r--bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentassist/StructuredContentAssistant.java143
6 files changed, 0 insertions, 1035 deletions
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentassist/CompoundContentAssistProcessor.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentassist/CompoundContentAssistProcessor.java
deleted file mode 100644
index 204f0ea9d6..0000000000
--- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentassist/CompoundContentAssistProcessor.java
+++ /dev/null
@@ -1,422 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-
-package org.eclipse.wst.sse.ui.internal.contentassist;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.jface.contentassist.IContentAssistSubjectControl;
-import org.eclipse.jface.contentassist.ISubjectControlContentAssistProcessor;
-import org.eclipse.jface.contentassist.ISubjectControlContextInformationValidator;
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
-import org.eclipse.jface.text.contentassist.IContextInformation;
-import org.eclipse.jface.text.contentassist.IContextInformationValidator;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.wst.sse.ui.internal.IReleasable;
-
-/**
- * A processor that aggregates the proposals of multiple other processors.
- * When proposals are requested, the contained processors are queried in the
- * order they were added to the compound object. Copied from
- * org.eclipse.jdt.internal.ui.text.CompoundContentAssistProcessor.
- * Modification was made to add a dispose() method.
- */
-class CompoundContentAssistProcessor implements IContentAssistProcessor, ISubjectControlContentAssistProcessor {
-
- private static class WrappedContextInformation implements IContextInformation {
- private IContextInformation fInfo;
- private IContentAssistProcessor fProcessor;
-
- WrappedContextInformation(IContextInformation info, IContentAssistProcessor processor) {
- fInfo = info;
- fProcessor = processor;
- }
-
- /*
- * @see java.lang.Object#equals(java.lang.Object)
- */
- public boolean equals(Object obj) {
- return fInfo.equals(obj);
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContextInformation#getContextDisplayString()
- */
- public String getContextDisplayString() {
- return fInfo.getContextDisplayString();
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContextInformation#getImage()
- */
- public Image getImage() {
- return fInfo.getImage();
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContextInformation#getInformationDisplayString()
- */
- public String getInformationDisplayString() {
- return fInfo.getInformationDisplayString();
- }
-
- /*
- * @see java.lang.Object#hashCode()
- */
- public int hashCode() {
- return fInfo.hashCode();
- }
-
- /*
- * @see java.lang.Object#toString()
- */
- public String toString() {
- return fInfo.toString();
- }
-
- IContentAssistProcessor getProcessor() {
- return fProcessor;
- }
- }
-
- private static class CompoundContentAssistValidator implements IContextInformationValidator {
- List fValidators = new ArrayList();
- IContextInformationValidator fValidator;
-
- void add(IContextInformationValidator validator) {
- fValidators.add(validator);
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContextInformationValidator#install(org.eclipse.jface.text.contentassist.IContextInformation,
- * org.eclipse.jface.text.ITextViewer, int)
- */
- public void install(IContextInformation info, ITextViewer viewer, int documentPosition) {
- // install either the validator in the info, or all validators
- fValidator = getValidator(info);
- if (fValidator != null)
- fValidator.install(info, viewer, documentPosition);
- else {
- for (Iterator it = fValidators.iterator(); it.hasNext();) {
- IContextInformationValidator v = (IContextInformationValidator) it.next();
- v.install(info, viewer, documentPosition);
- }
- }
- }
-
- IContextInformationValidator getValidator(IContextInformation info) {
- if (info instanceof WrappedContextInformation) {
- WrappedContextInformation wrap = (WrappedContextInformation) info;
- return wrap.getProcessor().getContextInformationValidator();
- }
-
- return null;
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContextInformationValidator#isContextInformationValid(int)
- */
- public boolean isContextInformationValid(int documentPosition) {
- // use either the validator in the info, or all validators
- boolean isValid = false;
- if (fValidator != null)
- isValid = fValidator.isContextInformationValid(documentPosition);
- else {
- for (Iterator it = fValidators.iterator(); it.hasNext();) {
- IContextInformationValidator v = (IContextInformationValidator) it.next();
- isValid |= v.isContextInformationValid(documentPosition);
- }
- }
- return isValid;
- }
-
- }
-
- private static class CompoundContentAssistValidatorEx extends CompoundContentAssistValidator implements ISubjectControlContextInformationValidator {
-
- /*
- * @see ISubjectControlContextInformationValidator#install(IContextInformation,
- * IContentAssistSubjectControl, int)
- */
- public void install(IContextInformation info, IContentAssistSubjectControl contentAssistSubjectControl, int documentPosition) {
- // install either the validator in the info, or all validators
- fValidator = getValidator(info);
- if (fValidator instanceof ISubjectControlContextInformationValidator)
- ((ISubjectControlContextInformationValidator) fValidator).install(info, contentAssistSubjectControl, documentPosition);
- else {
- for (Iterator it = fValidators.iterator(); it.hasNext();) {
- if (it.next() instanceof ISubjectControlContextInformationValidator)
- ((ISubjectControlContextInformationValidator) it.next()).install(info, contentAssistSubjectControl, documentPosition);
- }
- }
- }
-
- }
-
- private final Set fProcessors = new LinkedHashSet();
-
- /**
- * Creates a new instance.
- */
- public CompoundContentAssistProcessor() {
- }
-
- /**
- * Creates a new instance with one child processor.
- *
- * @param processor
- * the processor to add
- */
- public CompoundContentAssistProcessor(IContentAssistProcessor processor) {
- add(processor);
- }
-
- /**
- * Adds a processor to this compound processor.
- *
- * @param processor
- * the processor to add
- */
- public void add(IContentAssistProcessor processor) {
- Assert.isNotNull(processor);
- fProcessors.add(processor);
- }
-
- /**
- * Removes a processor from this compound processor.
- *
- * @param processor
- * the processor to remove
- */
- public void remove(IContentAssistProcessor processor) {
- fProcessors.remove(processor);
- }
-
- /**
- * Creates a new instance and adds all specified processors.
- *
- * @param processors
- */
- public CompoundContentAssistProcessor(IContentAssistProcessor[] processors) {
- for (int i = 0; i < processors.length; i++) {
- add(processors[i]);
- }
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer,
- * int)
- */
- public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
- List ret = new LinkedList();
- for (Iterator it = fProcessors.iterator(); it.hasNext();) {
- IContentAssistProcessor p = (IContentAssistProcessor) it.next();
- ICompletionProposal[] proposals = p.computeCompletionProposals(viewer, documentOffset);
- if (proposals != null)
- ret.addAll(Arrays.asList(proposals));
- }
- return (ICompletionProposal[]) ret.toArray(new ICompletionProposal[ret.size()]);
- }
-
- /**
- * {@inheritDoc}
- * <p>
- * The returned objects are wrapper objects around the real information
- * containers.
- * </p>
- *
- * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeContextInformation(org.eclipse.jface.text.ITextViewer,
- * int)
- */
- public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) {
- List ret = new LinkedList();
- for (Iterator it = fProcessors.iterator(); it.hasNext();) {
- IContentAssistProcessor p = (IContentAssistProcessor) it.next();
- IContextInformation[] informations = p.computeContextInformation(viewer, documentOffset);
- if (informations != null)
- for (int i = 0; i < informations.length; i++)
- ret.add(new WrappedContextInformation(informations[i], p));
- }
- return (IContextInformation[]) ret.toArray(new IContextInformation[ret.size()]);
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getCompletionProposalAutoActivationCharacters()
- */
- public char[] getCompletionProposalAutoActivationCharacters() {
- Set ret = new LinkedHashSet();
- for (Iterator it = fProcessors.iterator(); it.hasNext();) {
- IContentAssistProcessor p = (IContentAssistProcessor) it.next();
- char[] chars = p.getCompletionProposalAutoActivationCharacters();
- if (chars != null)
- for (int i = 0; i < chars.length; i++)
- ret.add(new Character(chars[i]));
- }
-
- char[] chars = new char[ret.size()];
- int i = 0;
- for (Iterator it = ret.iterator(); it.hasNext(); i++) {
- Character ch = (Character) it.next();
- chars[i] = ch.charValue();
- }
- return chars;
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationAutoActivationCharacters()
- */
- public char[] getContextInformationAutoActivationCharacters() {
- Set ret = new LinkedHashSet();
- for (Iterator it = fProcessors.iterator(); it.hasNext();) {
- IContentAssistProcessor p = (IContentAssistProcessor) it.next();
- char[] chars = p.getContextInformationAutoActivationCharacters();
- if (chars != null)
- for (int i = 0; i < chars.length; i++)
- ret.add(new Character(chars[i]));
- }
-
- char[] chars = new char[ret.size()];
- int i = 0;
- for (Iterator it = ret.iterator(); it.hasNext(); i++) {
- Character ch = (Character) it.next();
- chars[i] = ch.charValue();
- }
- return chars;
- }
-
- /**
- * Returns the first non- <code>null</code> error message of any
- * contained processor, or <code>null</code> if no processor has an
- * error message.
- *
- * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getErrorMessage()
- * @return {@inheritDoc}
- */
- public String getErrorMessage() {
- for (Iterator it = fProcessors.iterator(); it.hasNext();) {
- IContentAssistProcessor p = (IContentAssistProcessor) it.next();
- String err = p.getErrorMessage();
- if (err != null)
- return err;
- }
- return null;
- }
-
- /**
- * {@inheritDoc}
- * <p>
- * The returned validator is a wrapper around the validators provided by
- * the child processors.
- * </p>
- *
- * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationValidator()
- */
- public IContextInformationValidator getContextInformationValidator() {
- boolean hasValidator = false;
- boolean hasExtension = false;
- for (Iterator it = fProcessors.iterator(); it.hasNext();) {
- IContentAssistProcessor p = (IContentAssistProcessor) it.next();
- IContextInformationValidator v = p.getContextInformationValidator();
- if (v instanceof ISubjectControlContextInformationValidator) {
- hasExtension = true;
- break;
- }
- else if (v != null) {
- hasValidator = true;
- }
- }
-
- CompoundContentAssistValidator validator = null;
- if (hasExtension)
- validator = new CompoundContentAssistValidatorEx();
- else if (hasValidator)
- validator = new CompoundContentAssistValidator();
-
- if (validator != null)
- for (Iterator it = fProcessors.iterator(); it.hasNext();) {
- IContentAssistProcessor p = (IContentAssistProcessor) it.next();
- IContextInformationValidator v = p.getContextInformationValidator();
- if (v != null)
- validator.add(v);
- }
-
- return validator;
- }
-
- /*
- * @see ISubjectControlContentAssistProcessor#computeCompletionProposals(IContentAssistSubjectControl,
- * int)
- */
- public ICompletionProposal[] computeCompletionProposals(IContentAssistSubjectControl contentAssistSubjectControl, int documentOffset) {
- List ret = new LinkedList();
- for (Iterator it = fProcessors.iterator(); it.hasNext();) {
- Object o = it.next();
- if (o instanceof ISubjectControlContentAssistProcessor) {
- ISubjectControlContentAssistProcessor p = (ISubjectControlContentAssistProcessor) o;
- ICompletionProposal[] proposals = p.computeCompletionProposals(contentAssistSubjectControl, documentOffset);
- if (proposals != null)
- ret.addAll(Arrays.asList(proposals));
- }
- }
-
- return (ICompletionProposal[]) ret.toArray(new ICompletionProposal[ret.size()]);
- }
-
- /**
- * {@inheritDoc}
- * <p>
- * The returned objects are wrapper objects around the real information
- * containers.
- * </p>
- *
- * @see org.eclipse.jface.contentassist.ISubjectControlContentAssistProcessor#computeContextInformation(org.eclipse.jface.text.contentassist.IContentAssistSubject,
- * int)
- */
- public IContextInformation[] computeContextInformation(IContentAssistSubjectControl contentAssistSubjectControl, int documentOffset) {
- List ret = new LinkedList();
- for (Iterator it = fProcessors.iterator(); it.hasNext();) {
- Object o = it.next();
- if (o instanceof ISubjectControlContentAssistProcessor) {
- ISubjectControlContentAssistProcessor p = (ISubjectControlContentAssistProcessor) o;
- IContextInformation[] informations = p.computeContextInformation(contentAssistSubjectControl, documentOffset);
- if (informations != null)
- for (int i = 0; i < informations.length; i++)
- ret.add(new WrappedContextInformation(informations[i], p));
- }
- }
- return (IContextInformation[]) ret.toArray(new IContextInformation[ret.size()]);
- }
-
- /**
- * Dispose of any content assist processors that need disposing
- */
- public void dispose() {
- // go through list of content assist processors and dispose
- for (Iterator it = fProcessors.iterator(); it.hasNext();) {
- IContentAssistProcessor p = (IContentAssistProcessor) it.next();
- if (p instanceof IReleasable) {
- ((IReleasable) p).release();
- }
- }
- fProcessors.clear();
- }
-}
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentassist/ContentAssistUtils.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentassist/ContentAssistUtils.java
deleted file mode 100644
index 54f12c10ae..0000000000
--- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentassist/ContentAssistUtils.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.sse.ui.internal.contentassist;
-
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.wst.sse.core.StructuredModelManager;
-import org.eclipse.wst.sse.core.internal.provisional.IModelManager;
-import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
-import org.eclipse.wst.sse.core.internal.provisional.IndexedRegion;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
-import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
-
-
-/**
- * @author pavery
- *
- */
-public class ContentAssistUtils {
-
- /**
- * Returns the closest IndexedRegion for the offset and viewer allowing
- * for differences between viewer offsets and model positions. note: this
- * method returns an IndexedRegion for read only
- *
- * @param viewer
- * the viewer whose document is used to compute the proposals
- * @param documentOffset
- * an offset within the document for which completions should
- * be computed
- * @return an IndexedRegion
- */
- public static IndexedRegion getNodeAt(ITextViewer viewer, int documentOffset) {
-
- if (viewer == null)
- return null;
-
- IndexedRegion node = null;
- IModelManager mm = StructuredModelManager.getModelManager();
- IStructuredModel model = null;
- if (mm != null)
- model = mm.getExistingModelForRead(viewer.getDocument());
- try {
- if (model != null) {
- int lastOffset = documentOffset;
- node = model.getIndexedRegion(documentOffset);
- while (node == null && lastOffset >= 0) {
- lastOffset--;
- node = model.getIndexedRegion(lastOffset);
- }
- }
- } finally {
- if (model != null)
- model.releaseFromRead();
- }
- return node;
- }
-
- /**
- * Returns the closest IStructuredDocumentRegion for the offest and
- * viewer.
- *
- * @param viewer
- * @param documentOffset
- * @return the closest IStructuredDocumentRegion for the offest and
- * viewer.
- */
- public static IStructuredDocumentRegion getStructuredDocumentRegion(ITextViewer viewer, int documentOffset) {
- IStructuredDocumentRegion sdRegion = null;
- if (viewer == null || viewer.getDocument() == null)
- return null;
-
- int lastOffset = documentOffset;
- IStructuredDocument doc = (IStructuredDocument) viewer.getDocument();
- sdRegion = doc.getRegionAtCharacterOffset(documentOffset);
- while (sdRegion == null && lastOffset >= 0) {
- lastOffset--;
- sdRegion = doc.getRegionAtCharacterOffset(lastOffset);
- }
- return sdRegion;
- }
-
-}
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentassist/CustomCompletionProposal.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentassist/CustomCompletionProposal.java
deleted file mode 100644
index 013799b989..0000000000
--- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentassist/CustomCompletionProposal.java
+++ /dev/null
@@ -1,333 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.sse.ui.internal.contentassist;
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.ITextViewerExtension5;
-import org.eclipse.jface.text.contentassist.CompletionProposal;
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.jface.text.contentassist.ICompletionProposalExtension;
-import org.eclipse.jface.text.contentassist.ICompletionProposalExtension2;
-import org.eclipse.jface.text.contentassist.IContextInformation;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.wst.sse.core.internal.util.Debug;
-
-/**
- * An implementation of ICompletionProposal whose values can be read after
- * creation.
- */
-public class CustomCompletionProposal implements ICompletionProposal, ICompletionProposalExtension, ICompletionProposalExtension2, IRelevanceCompletionProposal {
-
- private String fAdditionalProposalInfo;
-
- private IContextInformation fContextInformation;
-
- private int fCursorPosition = 0;
-
- private String fDisplayString;
-
- private Image fImage;
-
- private int fOriginalReplacementLength;
-
- private int fRelevance = IRelevanceConstants.R_NONE;
-
- private int fReplacementLength = 0;
-
- private int fReplacementOffset = 0;
-
- private String fReplacementString = null;
-
- private boolean fUpdateLengthOnValidate;
-
- private char[] fTriggers;
-
- /**
- * Constructor with relevance and replacement length update flag.
- *
- * If the <code>updateReplacementLengthOnValidate</code> flag is true,
- * then when the user types, the replacement length will be incremented by
- * the number of new characters inserted from the original position.
- * Otherwise the replacement length will not change on validate.
- *
- * ex.
- *
- * <tag |name="attr"> - the replacement length is 4 <tag i|name="attr"> -
- * the replacement length is now 5 <tag id|name="attr"> - the replacement
- * length is now 6 <tag |name="attr"> - the replacementlength is now 4 again
- * <tag |name="attr"> - the replacment length remains 4
- *
- */
- public CustomCompletionProposal(String replacementString, int replacementOffset, int replacementLength, int cursorPosition, Image image, String displayString,
- IContextInformation contextInformation, String additionalProposalInfo, int relevance, boolean updateReplacementLengthOnValidate) {
- fReplacementString = replacementString;
- fReplacementOffset = replacementOffset;
- fReplacementLength = replacementLength;
- fCursorPosition = cursorPosition;
- fImage = image;
- fDisplayString = displayString;
- fContextInformation = contextInformation;
- fAdditionalProposalInfo = additionalProposalInfo;
- fRelevance = relevance;
- fUpdateLengthOnValidate = updateReplacementLengthOnValidate;
- fOriginalReplacementLength = fReplacementLength;
- }
-
- public CustomCompletionProposal(String replacementString, int replacementOffset, int replacementLength, int cursorPosition, Image image, String displayString,
- IContextInformation contextInformation, String additionalProposalInfo, int relevance) {
- this(replacementString, replacementOffset, replacementLength, cursorPosition, image, displayString, contextInformation, additionalProposalInfo, relevance, true);
- }
-
- public void apply(IDocument document) {
- CompletionProposal proposal = new CompletionProposal(getReplacementString(), getReplacementOffset(), getReplacementLength(), getCursorPosition(), getImage(), getDisplayString(),
- getContextInformation(), getAdditionalProposalInfo());
- proposal.apply(document);
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension#apply(org.eclipse.jface.text.IDocument,
- * char, int)
- */
- public void apply(IDocument document, char trigger, int offset) {
- CompletionProposal proposal = new CompletionProposal(getReplacementString(), getReplacementOffset(), getReplacementLength(), getCursorPosition(), getImage(), getDisplayString(),
- getContextInformation(), getAdditionalProposalInfo());
- // we currently don't do anything special for which character
- // selected the proposal, and where the cursor offset is
- // but we might in the future...
- proposal.apply(document);
- // we want to ContextInformationPresenter.updatePresentation() here
- }
-
- public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) {
- IDocument document = viewer.getDocument();
- // CMVC 252634 to compensate for "invisible" initial region
- int caretOffset = viewer.getTextWidget().getCaretOffset();
- if (viewer instanceof ITextViewerExtension5) {
- ITextViewerExtension5 extension = (ITextViewerExtension5) viewer;
- caretOffset = extension.widgetOffset2ModelOffset(caretOffset);
- } else {
- caretOffset = viewer.getTextWidget().getCaretOffset() + viewer.getVisibleRegion().getOffset();
- }
-
- if (caretOffset == getReplacementOffset()) {
- apply(document);
- } else {
- // replace the text without affecting the caret Position as this
- // causes the cursor to move on its own
- try {
- int endOffsetOfChanges = getReplacementString().length() + getReplacementOffset();
- // Insert the portion of the new text that comes after the
- // current caret position
- if (endOffsetOfChanges >= caretOffset) {
- int postCaretReplacementLength = getReplacementOffset() + getReplacementLength() - caretOffset;
- int preCaretReplacementLength = getReplacementString().length() - (endOffsetOfChanges - caretOffset);
- if (postCaretReplacementLength < 0) {
- if (Debug.displayWarnings) {
- System.out.println("** postCaretReplacementLength was negative: " + postCaretReplacementLength); //$NON-NLS-1$
- }
- // This is just a quick fix while I figure out what
- // replacement length is supposed to be
- // in each case, otherwise we'll get negative
- // replacment length sometimes
- postCaretReplacementLength = 0;
- }
- document.replace(caretOffset, postCaretReplacementLength, getReplacementString().substring(preCaretReplacementLength));
- }
- // Insert the portion of the new text that comes before the
- // current caret position
- // Done second since offsets would change for the post text
- // otherwise
- // Outright insertions are handled here
- if (caretOffset > getReplacementOffset()) {
- int preCaretTextLength = caretOffset - getReplacementOffset();
- document.replace(getReplacementOffset(), preCaretTextLength, getReplacementString().substring(0, preCaretTextLength));
- }
- } catch (BadLocationException x) {
- apply(document);
- } catch (StringIndexOutOfBoundsException e) {
- apply(document);
- }
- }
- }
-
- public String getAdditionalProposalInfo() {
- // return fProposal.getAdditionalProposalInfo();
- return fAdditionalProposalInfo;
- }
-
- public IContextInformation getContextInformation() {
- // return fProposal.getContextInformation();
- return fContextInformation;
- }
-
- public void setContextInformation(IContextInformation contextInfo) {
- fContextInformation = contextInfo;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension#getContextInformationPosition()
- */
- public int getContextInformationPosition() {
- return getCursorPosition();
- }
-
- public int getCursorPosition() {
- return fCursorPosition;
- }
-
- public void setCursorPosition(int pos) {
- fCursorPosition = pos;
- }
-
- public void setDisplayString(String newDisplayString) {
- fDisplayString = newDisplayString;
- }
-
- public String getDisplayString() {
- // return fProposal.getDisplayString();
- return fDisplayString;
- }
-
- public Image getImage() {
- // return fProposal.getImage();
- return fImage;
- }
-
- public int getRelevance() {
- return fRelevance;
- }
-
- public void setReplacementLength(int newReplacementLength) {
- fReplacementLength = newReplacementLength;
- }
- public int getReplacementLength() {
- return fReplacementLength;
- }
-
- public int getReplacementOffset() {
- return fReplacementOffset;
- }
-
- public String getReplacementString() {
- return fReplacementString;
- }
-
- public Point getSelection(IDocument document) {
- // return fProposal.getSelection(document);
- CompletionProposal proposal = new CompletionProposal(getReplacementString(), getReplacementOffset(), getReplacementLength(), getCursorPosition(), getImage(), getDisplayString(),
- getContextInformation(), getAdditionalProposalInfo());
- return proposal.getSelection(document);
- }
-
- /**
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension#getTriggerCharacters()
- */
-
- public char[] getTriggerCharacters() {
- return fTriggers;
- }
-
- public void setTriggerCharacters(char[] triggers) {
- fTriggers = triggers;
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension#isValidFor(org.eclipse.jface.text.IDocument,
- * int)
- */
- public boolean isValidFor(IDocument document, int offset) {
- return validate(document, offset, null);
- }
-
- /**
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#selected(org.eclipse.jface.text.ITextViewer,
- * boolean)
- */
- public void selected(ITextViewer viewer, boolean smartToggle) {
- }
-
- // code is borrowed from JavaCompletionProposal
- protected boolean startsWith(IDocument document, int offset, String word) {
-
- int wordLength = word == null ? 0 : word.length();
- if (offset > fReplacementOffset + wordLength)
- return false;
-
- try {
- int length = offset - fReplacementOffset;
- String start = document.get(fReplacementOffset, length);
-
- return word.substring(0, length).equalsIgnoreCase(start);
- } catch (BadLocationException x) {
- }
-
- return false;
- }
-
- /**
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#unselected(org.eclipse.jface.text.ITextViewer)
- */
- public void unselected(ITextViewer viewer) {
- }
-
- /**
- * borrowed from JavaCompletionProposal
- *
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#validate(org.eclipse.jface.text.IDocument,
- * int, org.eclipse.jface.text.DocumentEvent)
- */
- public boolean validate(IDocument document, int offset, DocumentEvent event) {
- if (offset < fReplacementOffset)
- return false;
- boolean validated = startsWith(document, offset, fDisplayString);
-
- if (fUpdateLengthOnValidate) {
-
- // it would be better to use "originalCursorPosition" instead of
- // getReplacementOffset(), but we don't have that info.
- int newLength = offset - getReplacementOffset();
- int delta = newLength - fOriginalReplacementLength;
- fReplacementLength = delta + fOriginalReplacementLength;
-
- // if it's an attribute value, replacement offset is
- // going to be one off from the actual cursor offset...
- char firstChar = document.get().charAt(getReplacementOffset());
- if(firstChar == '"' || firstChar == '\'')
- fReplacementLength ++;
- }
- return validated;
- }
-
- /**
- * @param replacementOffset The fReplacementOffset to set.
- */
- public void setReplacementOffset(int replacementOffset) {
- fReplacementOffset = replacementOffset;
- }
- /**
- * @param replacementString The fReplacementString to set.
- */
- public void setReplacementString(String replacementString) {
- fReplacementString = replacementString;
- }
-}
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentassist/IRelevanceCompletionProposal.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentassist/IRelevanceCompletionProposal.java
deleted file mode 100644
index d67b10e63e..0000000000
--- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentassist/IRelevanceCompletionProposal.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.sse.ui.internal.contentassist;
-
-
-/**
- * CompletionProposal with a relevance value. The relevance value is used to
- * sort the completion proposals. Proposals with higher relevance should be
- * listed before proposals with lower relevance.
- *
- * @author pavery
- */
-public interface IRelevanceCompletionProposal {
- /**
- * Returns the relevance of the proposal.
- */
- int getRelevance();
-}
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentassist/IRelevanceConstants.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentassist/IRelevanceConstants.java
deleted file mode 100644
index ba5a16ed30..0000000000
--- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentassist/IRelevanceConstants.java
+++ /dev/null
@@ -1,17 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2001, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.sse.ui.internal.contentassist;
-
-public interface IRelevanceConstants {
- int R_NONE = 0;
-}
diff --git a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentassist/StructuredContentAssistant.java b/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentassist/StructuredContentAssistant.java
deleted file mode 100644
index 30ee6a5d9f..0000000000
--- a/bundles/org.eclipse.wst.sse.ui/src/org/eclipse/wst/sse/ui/internal/contentassist/StructuredContentAssistant.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- * Jens Lukowski/Innoopract - initial renaming/restructuring
- *
- *******************************************************************************/
-package org.eclipse.wst.sse.ui.internal.contentassist;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.jface.text.contentassist.ContentAssistant;
-import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
-import org.eclipse.wst.sse.ui.internal.ExtendedConfigurationBuilder;
-
-public class StructuredContentAssistant extends ContentAssistant {
- private static final String CONTENT_ASSIST_PROCESSOR_EXTENDED_ID = "contentassistprocessor"; //$NON-NLS-1$
-
- /**
- * personal list of content assist processors
- */
- private Map fProcessors;
- /**
- * list of partition types where extended processors have been installed
- */
- private List fInstalledExtendedContentTypes;
-
- /**
- * Each set content assist processor is placed inside a
- * CompoundContentAssistProcessor which allows multiple processors per
- * partition type
- *
- * @param processor
- * the content assist processor to register, or
- * <code>null</code> to remove an existing one
- * @param contentType
- * the content type under which to register
- */
- public void setContentAssistProcessor(IContentAssistProcessor processor, String partitionType) {
- if (fProcessors == null)
- fProcessors = new HashMap();
-
- CompoundContentAssistProcessor compoundProcessor = getExistingContentAssistProcessor(partitionType);
-
- // if processor is null, you want to remove all processors of
- // contentType
- if (processor == null && compoundProcessor != null) {
- compoundProcessor.dispose();
- fProcessors.remove(partitionType);
- compoundProcessor = null;
- }
- if (processor != null) {
- // create a new compoundprocess if there already isnt one
- if (compoundProcessor == null) {
- compoundProcessor = new CompoundContentAssistProcessor();
- }
- // add processor to compound processor
- compoundProcessor.add(processor);
- // add compound procesor to processors list (will replace old one,
- // even if same instance)
- fProcessors.put(partitionType, compoundProcessor);
- }
- super.setContentAssistProcessor(compoundProcessor, partitionType);
- }
-
- private CompoundContentAssistProcessor getExistingContentAssistProcessor(String partitionType) {
- CompoundContentAssistProcessor compoundContentAssistProcessor = null;
- IContentAssistProcessor processor = super.getContentAssistProcessor(partitionType);
- if (processor != null) {
- if (processor instanceof CompoundContentAssistProcessor) {
- compoundContentAssistProcessor = (CompoundContentAssistProcessor) processor;
- }
- else {
- throw new IllegalStateException("StructuredContentAssistant use CompoundContentAssistProcessor"); //$NON-NLS-1$
- }
- }
- return compoundContentAssistProcessor;
-
- }
-
- /**
- * Returns the content assist processor to be used for the given content
- * type. Also installs any content assist processors that were added by
- * extension point.
- *
- * @param contentType
- * the type of the content for which this content assistant is
- * to be requested
- * @return an instance content assist processor or <code>null</code> if
- * none exists for the specified content type
- */
- public IContentAssistProcessor getContentAssistProcessor(String partitionType) {
- if (fInstalledExtendedContentTypes == null || !fInstalledExtendedContentTypes.contains(partitionType)) {
- // get extended content assist processors that have not already
- // been set
- List processors = ExtendedConfigurationBuilder.getInstance().getConfigurations(CONTENT_ASSIST_PROCESSOR_EXTENDED_ID, partitionType);
- if (processors != null && !processors.isEmpty()) {
- Iterator iter = processors.iterator();
- while (iter.hasNext()) {
- IContentAssistProcessor processor = (IContentAssistProcessor) iter.next();
- setContentAssistProcessor(processor, partitionType);
- }
- }
- // add partition type to list of extended partition types
- // installed (regardless of whether or not any extended content
- // assist processors were installed because dont want to look it
- // up every time)
- if (fInstalledExtendedContentTypes == null)
- fInstalledExtendedContentTypes = new ArrayList();
- fInstalledExtendedContentTypes.add(partitionType);
- }
-
- IContentAssistProcessor processor = super.getContentAssistProcessor(partitionType);
- return processor;
- }
-
- public void uninstall() {
- // dispose of all content assist processors
- if (fProcessors != null && !fProcessors.isEmpty()) {
- Collection collection = fProcessors.values();
- Iterator iter = collection.iterator();
- while (iter.hasNext()) {
- ((CompoundContentAssistProcessor) iter.next()).dispose();
- }
- fProcessors.clear();
- }
- // clear out list of installed content types
- if (fInstalledExtendedContentTypes != null) {
- fInstalledExtendedContentTypes.clear();
- }
- super.uninstall();
- }
-}

Back to the top