Package org.carrot2.workbench.editors.impl.numeric

Source Code of org.carrot2.workbench.editors.impl.numeric.ReadOnlyEditor

/*
* Carrot2 project.
*
* Copyright (C) 2002-2014, Dawid Weiss, Stanisław Osiński.
* All rights reserved.
*
* Refer to the full license file "carrot2.LICENSE"
* in the root folder of the repository checkout or at:
* http://www.carrot2.org/carrot2.LICENSE
*/

package org.carrot2.workbench.editors.impl.numeric;

import java.util.Map;

import org.carrot2.workbench.core.helpers.GUIFactory;
import org.carrot2.workbench.editors.*;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;

/**
* An dummy editor for read-only numerics.
*/
final class ReadOnlyEditor extends AttributeEditorAdapter
{
    /** */
    private Text text;
   
    /** */
    private Object lastValue;

    @Override
    protected AttributeEditorInfo init(Map<String,Object> defaultValues)
    {
        return new AttributeEditorInfo(1, false);
    }
   
    /*
     * Return the current editor value.
     */
    @Override
    public Object getValue()
    {
        return lastValue;
    }

    @Override
    public void setValue(Object object)
    {
        if (lastValue == object)
        {
            return;
        }

        this.lastValue = object;
        this.text.setText(lastValue == null ? "(null)" : lastValue.toString());

        fireAttributeChanged(new AttributeEvent(this));
    }

    /*
     *
     */
    @Override
    public void createEditor(Composite parent, int gridColumns)
    {
        createText(parent, gridColumns);
    }

    /**
     * Create the scale control.
     */
    private void createText(Composite parent, int gridColumns)
    {
        final GridDataFactory factory = GUIFactory.editorGridData();

        final GridData layoutData = factory.create();
        layoutData.horizontalSpan = gridColumns;
        layoutData.grabExcessHorizontalSpace = false;
        layoutData.verticalAlignment = SWT.CENTER;

        text = new Text(parent, SWT.RIGHT | SWT.SINGLE);
        text.setEnabled(false);
        text.setLayoutData(layoutData);
    }
}
TOP

Related Classes of org.carrot2.workbench.editors.impl.numeric.ReadOnlyEditor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.