]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.browsing.ui.swt/src/org/simantics/browsing/ui/swt/contentassist/NamedObjectContentProposal.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.browsing.ui.swt / src / org / simantics / browsing / ui / swt / contentassist / NamedObjectContentProposal.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2012 Association for Decentralized Information Management
3  * in Industry THTH ry.
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.browsing.ui.swt.contentassist;
13
14 /**
15  * @author Tuukka Lehtonen
16  */
17 public class NamedObjectContentProposal implements INamedObjectContentProposal {
18
19     private final NamedObject<?> object;
20     private final int         position;
21
22     public NamedObjectContentProposal(NamedObject<?> object, int position) {
23         this.object = object;
24         this.position = position;
25     }
26
27     @Override
28     public INamedObject getNamedObject() {
29         return object;
30     }
31
32     @SuppressWarnings("unchecked")
33     public <T> T getObject() {
34         return (T) object.getObject();
35     }
36
37     @Override
38     public String getContent() {
39         return object.getName().substring(position);
40     }
41
42     @Override
43     public int getCursorPosition() {
44         return object.getName().length();
45     }
46
47     @Override
48     public String getLabel() {
49         return object.getLabel();
50     }
51
52     @Override
53     public String getDescription() {
54         return object.getDescription();
55     }
56
57     @Override
58     public String toString() {
59         return getClass().getSimpleName() + "[" + object.toString() + "]";
60     }
61
62 }