Package de.innovationgate.eclipse.editors.models

Source Code of de.innovationgate.eclipse.editors.models.WGPositioningMetaFieldDefinitionModel$Positioning

/*******************************************************************************
* Copyright (c) 2009, 2010 Innovation Gate GmbH.
* 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:
*     Innovation Gate GmbH - initial API and implementation
******************************************************************************/

package de.innovationgate.eclipse.editors.models;

import java.util.AbstractList;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import net.java.dev.genesis.annotation.DataProvider;
import net.java.dev.genesis.annotation.NotBound;
import de.innovationgate.eclipse.editors.design.dialogs.AddContentTypeMetaDefinitionDialog;
import de.innovationgate.eclipse.utils.ui.AbstractGenesisBoundObject;
import de.innovationgate.eclipse.utils.ui.model.WGASchemaDefinitionModel;
import de.innovationgate.utils.WGUtils;
import de.innovationgate.webgate.api.WGContentType;
import de.innovationgate.webgate.api.schemadef.WGContentTypeDefinition;
import de.innovationgate.webgate.api.schemadef.WGMetaFieldDefinition;
import de.innovationgate.wga.model.KeyValueBean;

public class WGPositioningMetaFieldDefinitionModel extends WGContentTypeDefinitionMetaDataModel {
   
    public WGPositioningMetaFieldDefinitionModel(WGASchemaDefinitionModel model) {
        super(model);
    }

    public static class Positioning extends KeyValueBean<String, String> {

        public Positioning(String key, String value) {
            super(key, value);
        }
       
    };
   
    public static Map<String,Positioning> POSITIONINGS = new HashMap<String, Positioning>();
    static {
        POSITIONINGS.put(WGContentType.POSITIONING_EVERYWHERE, new Positioning(WGContentType.POSITIONING_EVERYWHERE, "anywhere"));
        POSITIONINGS.put(WGContentType.POSITIONING_ROOTENTRIES, new Positioning(WGContentType.POSITIONING_ROOTENTRIES, "only root entries"));
        POSITIONINGS.put(WGContentType.POSITIONING_CHILDENTRIES, new Positioning(WGContentType.POSITIONING_CHILDENTRIES, "only child entries"));
        POSITIONINGS.put(WGContentType.POSITIONING_FIXEDPARENTS, new Positioning(WGContentType.POSITIONING_FIXEDPARENTS, "only fixed parents"));
        POSITIONINGS.put(WGContentType.POSITIONING_FIXEDPARENTTYPES, new Positioning(WGContentType.POSITIONING_FIXEDPARENTTYPES, "only parents with fixed contenttype"));
    }
   
    public String getName() {
        return AddContentTypeMetaDefinitionDialog.METADATA_DEFINITION_LABELS.get(_bean.getName());
    }
   
    public void setName(String name) {
        // noop
    }
   
    public void setPositioning(Positioning pos) {       
        _bean.setValue(pos.getKey());
        fireBeanChanged();
    }
   
    public Positioning getPositioning() {
        String value = (String)_bean.getSingleValue();
        if (value != null && !value.trim().equals("")) {
            return POSITIONINGS.get(value);
        } else {
            return POSITIONINGS.get(WGContentType.POSITIONING_EVERYWHERE);
        }
    }
   
    @DataProvider(objectField = "positioning")
    public List<Positioning> populatePositionings() {
        List<Positioning> list = new ArrayList<Positioning>(POSITIONINGS.values());
        return WGUtils.sortByProperty(list, "value");
    }
   
    @SuppressWarnings("unchecked")
    @NotBound
    public List<String> getAllowedPositions(WGContentTypeDefinition ctDef) {
        Iterator<WGMetaFieldDefinition> ctDefMetas = ctDef.getMetadata().iterator();
        WGMetaFieldDefinition allowedPosDef = null;
        while (ctDefMetas.hasNext()) {
            WGMetaFieldDefinition metaFieldDef = ctDefMetas.next();
            if (metaFieldDef.getName().equals(WGContentType.META_ALLOWED_POSITIONS)) {
                allowedPosDef = metaFieldDef;
                break;
            }
        }
       
        if (allowedPosDef == null) {
            allowedPosDef = new WGMetaFieldDefinition(WGContentType.META_ALLOWED_POSITIONS, new ArrayList<String>());
            ctDef.addMetadata(allowedPosDef);
        }                 
        return (List<String>)allowedPosDef.getValues();
    }
   
}
TOP

Related Classes of de.innovationgate.eclipse.editors.models.WGPositioningMetaFieldDefinitionModel$Positioning

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.