KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > text > correction > LinkedCorrectionProposal


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.jdt.internal.ui.text.correction;
12
13 import org.eclipse.swt.graphics.Image;
14
15 import org.eclipse.jdt.core.ICompilationUnit;
16 import org.eclipse.jdt.core.dom.ITypeBinding;
17 import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
18 import org.eclipse.jdt.core.dom.rewrite.ITrackedNodePosition;
19
20 /**
21  * A proposal for quick fixes and quick assists that works on a AST rewriter and enters the
22  * linked mode when the proposal is set up.
23  * Either a rewriter is directly passed in the constructor or method {@link #getRewrite()} is overridden
24  * to provide the AST rewriter that is evaluated to the document when the proposal is
25  * applied.
26  * @since 3.0
27  */

28 public class LinkedCorrectionProposal extends ASTRewriteCorrectionProposal {
29
30     /**
31      * Constructs a linked correction proposal.
32      * @param name The display name of the proposal.
33      * @param cu The compilation unit that is modified.
34      * @param rewrite The AST rewrite that is invoked when the proposal is applied
35      * <code>null</code> can be passed if {@link #getRewrite()} is overridden.
36      * @param relevance The relevance of this proposal.
37      * @param image The image that is displayed for this proposal or <code>null</code> if no
38      * image is desired.
39      */

40     public LinkedCorrectionProposal(String JavaDoc name, ICompilationUnit cu, ASTRewrite rewrite, int relevance, Image image) {
41         super(name, cu, rewrite, relevance, image);
42     }
43
44     /**
45      * Adds a linked position to be shown when the proposal is applied. All position with the
46      * same group id are linked.
47      * @param position The position to add.
48      * @param isFirst If set, the proposal is jumped to first.
49      * @param groupID The id of the group the proposal belongs to. All proposals in the same group
50      * are linked.
51      */

52     public void addLinkedPosition(ITrackedNodePosition position, boolean isFirst, String JavaDoc groupID) {
53         getLinkedProposalModel().getPositionGroup(groupID, true).addPosition(position, isFirst);
54     }
55
56     /**
57      * Sets the end position of the linked mode to the end of the passed range.
58      * @param position The position that describes the end position of the linked mode.
59      */

60     public void setEndPosition(ITrackedNodePosition position) {
61         getLinkedProposalModel().setEndPosition(position);
62     }
63
64     /**
65      * Adds a linked position proposal to the group with the given id.
66      * @param groupID The id of the group that should present the proposal
67      * @param proposal The string to propose.
68      * @param image The image to show for the position proposal or <code>null</code> if
69      * no image is desired.
70      */

71     public void addLinkedPositionProposal(String JavaDoc groupID, String JavaDoc proposal, Image image) {
72         getLinkedProposalModel().getPositionGroup(groupID, true).addProposal(proposal, image, 10);
73     }
74     
75     /**
76      * Adds a linked position proposal to the group with the given id.
77      * @param groupID The id of the group that should present the proposal
78      * @param displayString The name of the proposal
79      * @param proposal The string to insert.
80      * @param image The image to show for the position proposal or <code>null</code> if
81      * no image is desired.
82      * @deprecated use {@link #addLinkedPositionProposal(String, String, Image)} instead
83      */

84     public void addLinkedPositionProposal(String JavaDoc groupID, String JavaDoc displayString, String JavaDoc proposal, Image image) {
85         addLinkedPositionProposal(groupID, proposal, image);
86     }
87
88     /**
89      * Adds a linked position proposal to the group with the given id.
90      * @param groupID The id of the group that should present the proposal
91      * @param type The binding to use as type name proposal.
92      */

93     public void addLinkedPositionProposal(String JavaDoc groupID, ITypeBinding type) {
94         getLinkedProposalModel().getPositionGroup(groupID, true).addProposal(type, getCompilationUnit(), 10);
95     }
96 }
97
Popular Tags