ParameterGUI.java :  » Content-Management-System » contelligent » de » finix » contelligent » client » gui » action » Java Open Source

Java Open Source » Content Management System » contelligent 
contelligent » de » finix » contelligent » client » gui » action » ParameterGUI.java
/*
 * Copyright 2001-2006 C:1 Financial Services GmbH
 *
 * This software is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License Version 2.1, as published by the Free Software Foundation.
 *
 * This software 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
 */

package de.finix.contelligent.client.gui.action;

import de.finix.contelligent.client.gui.AbstractGUI;
import de.finix.contelligent.client.gui.ComponentEditor;
import de.finix.contelligent.client.gui.ComponentRenderer;
import de.finix.contelligent.client.gui.UnsupportedGUIException;
import de.finix.contelligent.client.gui.property.PropertyEditor;
import de.finix.contelligent.client.i18n.Resources;

public class ParameterGUI extends AbstractGUI {

    private ParameterEditor parameterEditor = null;

    private PropertyEditor propertyEditor = null;

    private void assureParameterEditorCreated(boolean editable) {
        if (parameterEditor == null) {
            parameterEditor = new ParameterEditor();
            parameterEditor.setComponent(getComponent());
            parameterEditor.setView(getView());
            parameterEditor.setEditable(editable);
            parameterEditor.init();
        } else if (parameterEditor.isEditable() != editable) {
            // only change this, if neccessary as it may take quite some time...
            parameterEditor.setEditable(editable);
        }
    }

    private void assurePropertyEditorCreated(boolean editable) {
        if (propertyEditor == null) {
            propertyEditor = new PropertyEditor();
            propertyEditor.setComponent(getComponent());
            propertyEditor.setView(getView());
            propertyEditor.setEditable(editable);
            propertyEditor.setVisibleGroup(PropertyEditor.EDIT);
            propertyEditor.init();
        } else if (propertyEditor.isEditable() != editable) {
            // only change this, if neccessary as it may take quite some time...
            propertyEditor.setEditable(editable);
        }
    }

    public boolean isSupported(int type) {
        return (type == DEFAULT || type == TABLE);
    }

    public ComponentEditor getEditor(int type) throws UnsupportedGUIException {
        if (!isSupported(type)) {
            throw new UnsupportedGUIException(getComponent());
        }
        if (type == TABLE) {
            assureParameterEditorCreated(true);
            return parameterEditor;
        } else {
            assurePropertyEditorCreated(true);
            return propertyEditor;
        }
    }

    public ComponentRenderer getRenderer(int type) throws UnsupportedGUIException {
        if (!isSupported(type)) {
            throw new UnsupportedGUIException(getComponent());
        }
        if (type == TABLE) {
            assureParameterEditorCreated(false);
            return parameterEditor;
        } else {
            assurePropertyEditorCreated(false);
            return propertyEditor;
        }
    }

    public String getName() {
        return Resources.getLocalString("action_parameter_gui");
    }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.