view dwtx/jface/viewers/DecorationContext.d @ 104:04b47443bb01

Reworked the collection uses to make use of a wrapper collection that is compatible to the Java Collections. These new wrappers now use the tango.util.containers instead of the tango.util.collections.
author Frank Benoit <benoit@tionex.de>
date Thu, 07 Aug 2008 15:01:33 +0200
parents 46a6e0e6ccd4
children
line wrap: on
line source

/*******************************************************************************
 * Copyright (c) 2006, 2008 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 * Port to the D programming language:
 *     Frank Benoit <benoit@tionex.de>
 *******************************************************************************/
module dwtx.jface.viewers.DecorationContext;

import dwtx.jface.viewers.IDecorationContext;


import dwt.dwthelper.utils;
import dwtx.dwtxhelper.Collection;

/**
 * A concrete implementation of the {@link IDecorationContext} interface,
 * suitable for instantiating.
 * <p>
 * This class is not intended to be subclassed.
 * </p>
 * @since 3.2
 */
public class DecorationContext : IDecorationContext {

    /**
     * Constant that defines a default decoration context that has
     * no context ids associated with it.
     */
    public static const IDecorationContext DEFAULT_CONTEXT;
    static this(){
        DEFAULT_CONTEXT = new DecorationContext();
    }

    private Map properties;

    /**
     * Create a decoration context.
     */
    public this() {
        properties = new HashMap();
    }


    /* (non-Javadoc)
     * @see dwtx.jface.viewers.IDecorationContext#getProperty(java.lang.String)
     */
    public Object getProperty(String property) {
        return properties.get(stringcast(property));
    }

    /* (non-Javadoc)
     * @see dwtx.jface.viewers.IDecorationContext#getProperties()
     */
    public String[] getProperties() {
        return stringcast( properties.keySet().toArray() );
    }

    /**
     * Set the given property to the given value. Setting the value of
     * a property to <code>null</code> removes the property from
     * the context.
     * @param property the property
     * @param value the value of the property or <code>null</code>
     * if the property is to be removed.
     */
    public void putProperty(String property, Object value) {
        if (value is null) {
            properties.remove(stringcast(property));
        } else {
            properties.put(stringcast(property), value);
        }
    }
}