Package jease.cms.web.content.editor.property

Source Code of jease.cms.web.content.editor.property.ChoicePropertyEditor

/*
    Copyright (C) 2011 maik.jablonski@jease.org

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program 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 General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package jease.cms.web.content.editor.property;

import jease.cms.domain.property.ChoiceProperty;
import jease.cms.domain.property.Property;
import jease.cms.domain.property.Provider;
import jease.cms.service.Properties;
import jfix.util.Arrays;
import jfix.zk.Checklist;
import jfix.zk.Container;
import jfix.zk.Scrollbox;
import jfix.zk.Selectfield;

public class ChoicePropertyEditor extends Container implements
    PropertyEditor<ChoiceProperty> {

  private boolean setupProvider;
  private ChoiceProperty property;
  private Selectfield providerSelection = new Selectfield();
  private Checklist valueSelection = new Checklist();

  public ChoicePropertyEditor() {
  }

  public ChoiceProperty getProperty() {
    if (setupProvider) {
      property.setProvider((String) providerSelection.getSelectedValue());
    } else {
      property.setValue(Arrays.cast(valueSelection.getSelected(),
          String.class));
    }
    return property;
  }

  public void setProperty(ChoiceProperty property) {
    this.property = property;
    if (property.getProvider() != null) {
      Property provider = Properties.getByPath(property.getProvider());
      if (provider instanceof Provider) {
        String[] choices = ((Provider) provider).getValue();
        valueSelection.setSelection(choices, property.getValue());
        valueSelection.orientVertical();
        if (choices.length > 15) {
          setChild(new Scrollbox(valueSelection));
        } else {
          setChild(valueSelection);
        }
        return;
      }
    }
    setupProvider = true;
    providerSelection.setValues(Properties.getProviderPaths());
    setChild(providerSelection);
  }

}
TOP

Related Classes of jease.cms.web.content.editor.property.ChoicePropertyEditor

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.