view dwtx/jface/viewers/DecorationContext.d @ 70:46a6e0e6ccd4

Merge with d-fied sources of 3.4M7
author Frank Benoit <benoit@tionex.de>
date Thu, 22 May 2008 01:36:46 +0200
parents b6c35faf97c8
children 04b47443bb01
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 tango.util.collection.HashMap;
import tango.util.collection.model.Map;

import dwt.dwthelper.utils;

/**
 * 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!(String,Object) properties;

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


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

    /* (non-Javadoc)
     * @see dwtx.jface.viewers.IDecorationContext#getProperties()
     */
    public String[] getProperties() {
        String[] res;
        foreach( k,v; properties ){
            res ~= k;
        }
        return res;
    }

    /**
     * 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.removeKey(property);
        } else {
            properties.add(property, value);
        }
    }
}