KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > text > link > ProposalPosition


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.jface.text.link;
12
13 import java.util.Arrays JavaDoc;
14
15 import org.eclipse.jface.text.IDocument;
16 import org.eclipse.jface.text.contentassist.ICompletionProposal;
17
18 /**
19  * LinkedPosition with added completion proposals.
20  * <p>
21  * Clients may instantiate or extend this class.
22  * </p>
23  *
24  * @since 3.0
25  */

26 public class ProposalPosition extends LinkedPosition {
27
28     /**
29      * The proposals
30      */

31     private ICompletionProposal[] fProposals;
32
33     /**
34      * Creates a new instance.
35      *
36      * @param document the document
37      * @param offset the offset of the position
38      * @param length the length of the position
39      * @param sequence the iteration sequence rank
40      * @param proposals the proposals to be shown when entering this position
41      */

42     public ProposalPosition(IDocument document, int offset, int length, int sequence, ICompletionProposal[] proposals) {
43         super(document, offset, length, sequence);
44         fProposals= copy(proposals);
45     }
46
47     /**
48      * Creates a new instance, with no sequence number.
49      *
50      * @param document the document
51      * @param offset the offset of the position
52      * @param length the length of the position
53      * @param proposals the proposals to be shown when entering this position
54      */

55     public ProposalPosition(IDocument document, int offset, int length, ICompletionProposal[] proposals) {
56         super(document, offset, length, LinkedPositionGroup.NO_STOP);
57         fProposals= copy(proposals);
58     }
59
60     /*
61      * @since 3.1
62      */

63     private ICompletionProposal[] copy(ICompletionProposal[] proposals) {
64         if (proposals != null) {
65             ICompletionProposal[] copy= new ICompletionProposal[proposals.length];
66             System.arraycopy(proposals, 0, copy, 0, proposals.length);
67             return copy;
68         }
69         return null;
70     }
71
72     /*
73      * @see java.lang.Object#equals(java.lang.Object)
74      */

75     public boolean equals(Object JavaDoc o) {
76         if (o instanceof ProposalPosition) {
77             if (super.equals(o)) {
78                 return Arrays.equals(fProposals, ((ProposalPosition)o).fProposals);
79             }
80         }
81         return false;
82     }
83
84     /**
85      * Returns the proposals attached to this position. The returned array is owned by
86      * this <code>ProposalPosition</code> and may not be modified by clients.
87      *
88      * @return an array of choices, including the initial one. Callers must not
89      * modify it.
90      */

91     public ICompletionProposal[] getChoices() {
92         return fProposals;
93     }
94
95     /*
96      * @see org.eclipse.jdt.internal.ui.text.link.LinkedPosition#hashCode()
97      */

98     public int hashCode() {
99         return super.hashCode() | (fProposals == null ? 0 : fProposals.hashCode());
100     }
101 }
102
Popular Tags