Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'archive/org.eclipse.qvt.declarative.editor.imp.runtime/src/org/eclipse/imp/editor/SourceProposal.java')
-rw-r--r--archive/org.eclipse.qvt.declarative.editor.imp.runtime/src/org/eclipse/imp/editor/SourceProposal.java162
1 files changed, 162 insertions, 0 deletions
diff --git a/archive/org.eclipse.qvt.declarative.editor.imp.runtime/src/org/eclipse/imp/editor/SourceProposal.java b/archive/org.eclipse.qvt.declarative.editor.imp.runtime/src/org/eclipse/imp/editor/SourceProposal.java
new file mode 100644
index 000000000..9834acb1d
--- /dev/null
+++ b/archive/org.eclipse.qvt.declarative.editor.imp.runtime/src/org/eclipse/imp/editor/SourceProposal.java
@@ -0,0 +1,162 @@
+/*******************************************************************************
+* Copyright (c) 2007 IBM Corporation.
+* 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:
+* Robert Fuhrer (rfuhrer@watson.ibm.com) - initial API and implementation
+
+*******************************************************************************/
+
+/**
+ *
+ */
+package org.eclipse.imp.editor;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.Region;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.Point;
+
+public class SourceProposal implements ICompletionProposal {
+ /**
+ * The text shown to the user in the popup view
+ */
+ private final String fProposal;
+
+ /**
+ * The new text being added/substituted if the user accepts this proposal
+ */
+ private final String fNewText;
+
+ /**
+ * The prefix being completed.
+ */
+ private final String fPrefix;
+
+ /**
+ * The range of text being replaced.
+ */
+ private final Region fRange;
+
+ /**
+ * The offset at which the insertion point should be placed after completing
+ * using this proposal
+ */
+ private final int fCursorLoc;
+
+ /**
+ * Additional information displayed in the pop-up view to the right of the
+ * main proposal list view when this proposal is selected.
+ */
+ private final String fAdditionalInfo;
+
+ /**
+ * Create a new completion proposal.
+ * @param newText the actual replacement text for this proposal
+ * @param prefix the prefix being completed
+ * @param offset the starting character offset of the text to be replaced
+ */
+ public SourceProposal(String newText, String prefix, int offset) {
+ this(newText, newText, prefix, offset);
+ }
+
+ /**
+ * Create a new completion proposal.
+ * @param proposal the text to be shown in the popup view listing the proposals
+ * @param newText the actual replacement text for this proposal
+ * @param prefix the prefix being completed
+ * @param offset the starting character offset of the text to be replaced
+ */
+ public SourceProposal(String proposal, String newText, String prefix, int offset) {
+ this(proposal, newText, prefix, offset, offset + newText.length() - prefix.length());
+ }
+
+ /**
+ * Create a new completion proposal.
+ * @param proposal the text to be shown in the popup view listing the proposals
+ * @param newText the actual replacement text for this proposal
+ * @param prefix the prefix being completed
+ * @param offset the starting character offset of the text to be replaced
+ * @param cursorLoc the point at which to place the cursor after the replacement
+ */
+ public SourceProposal(String proposal, String newText, String prefix, int offset, int cursorLoc) {
+ this(proposal, newText, prefix, new Region(offset, 0), cursorLoc);
+ }
+
+ /**
+ * Create a new completion proposal.
+ * @param proposal the text to be shown in the popup view listing the proposals
+ * @param newText the actual replacement text for this proposal
+ * @param prefix the prefix being completed
+ * @param region the region of text to be replaced
+ * @param cursorLoc the point at which to place the cursor after the replacement
+ */
+ public SourceProposal(String proposal, String newText, String prefix, Region region, String addlInfo) {
+ this(proposal, newText, prefix, region, region.getOffset() + newText.length() - prefix.length(), addlInfo);
+ }
+
+ /**
+ * Create a new completion proposal.
+ * @param proposal the text to be shown in the popup view listing the proposals
+ * @param newText the actual replacement text for this proposal
+ * @param prefix the prefix being completed
+ * @param region the region of text to be replaced
+ * @param cursorLoc the point at which to place the cursor after the replacement
+ */
+ public SourceProposal(String proposal, String newText, String prefix, Region region, int cursorLoc) {
+ this(proposal, newText, prefix, region, cursorLoc, null);
+ }
+
+ /**
+ * Create a new completion proposal.
+ * @param proposal the text to be shown in the popup view listing the proposals
+ * @param newText the actual replacement text for this proposal
+ * @param prefix the prefix being completed
+ * @param region the region of text to be replaced
+ * @param cursorLoc the point at which to place the cursor after the replacement
+ * @param addlInfo the text to display in the pop-up view on the right when this
+ * proposal is selected
+ */
+ public SourceProposal(String proposal, String newText, String prefix, Region region, int cursorLoc, String addlInfo) {
+ fProposal= proposal;
+ fNewText= newText;
+ fPrefix= prefix;
+ fRange= region;
+ fCursorLoc= cursorLoc;
+ fAdditionalInfo= addlInfo;
+ }
+
+ public void apply(IDocument document) {
+ try {
+ document.replace(fRange.getOffset(), fRange.getLength(), fNewText.substring(fPrefix.length()));
+ } catch (BadLocationException e) {
+ e.printStackTrace();
+ }
+ }
+
+ public Point getSelection(IDocument document) {
+ return new Point(fCursorLoc, 0);
+ }
+
+ public String getDisplayString() {
+ return fProposal;
+ }
+
+ public String getAdditionalProposalInfo() {
+ return fAdditionalInfo;
+ }
+
+ public Image getImage() {
+ return null;
+ }
+
+ public IContextInformation getContextInformation() {
+ return null;
+ }
+}

Back to the top