/*
 * AutoCompleteListItem.java
 *
 * Copyright (C) 2002-2009 Takis Diakoumis
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 3
 * of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 *
 */

package org.executequery.gui.editor.autocomplete;

public class AutoCompleteListItem {

    private final String value;

    private final String description;
    
    private final AutoCompleteListItemType type;

    private final String displayValue;

    public AutoCompleteListItem(String value, String displayValue, String description,
            AutoCompleteListItemType type) {
        
        super();
        
        this.value = value;
        this.displayValue = displayValue;
        this.description = description;
        this.type = type;
    }

    public boolean isNothingProposed() {

        return (type == AutoCompleteListItemType.NOTHING_PROPOSED);
    }
    
    public boolean isKeyword() {
        
        return AutoCompleteListItemType.isKeyword(type);
    }
    
    public String getDisplayValue() {
        return displayValue;
    }
    
    public String getDescription() {
        return description;
    }
    
    public String getValue() {
        return value;
    }

    public String getInsertionValue() {
        
        if (type == AutoCompleteListItemType.DATABASE_TABLE_COLUMN) {
            
            int dotIndex = value.indexOf('.');
            return value.substring(dotIndex + 1);
        
        } else {
            
            return value;
        }
        
    }
    
    public AutoCompleteListItemType getType() {
        return type;
    }
 
    @Override
    public String toString() {
        return getDisplayValue();
    }
    
}

