All Downloads are FREE. Search and download functionalities are using the official Maven repository.

nl.cloudfarming.client.farm.model.FarmDetailsEditPanel Maven / Gradle / Ivy

There is a newer version: 13.03-beta
Show newest version
/**
 * Copyright (C) 2010-2012 Agrosense [email protected]
 *
 * Licensed under the Eclipse Public License - v 1.0 (the "License"); you may
 * not use this file except in compliance with the License. You may obtain a
 * copy of the License at
 *
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package nl.cloudfarming.client.farm.model;

import javax.swing.JTextField;
import nl.cloudfarming.client.model.IssuingAgency;
import nl.cloudfarming.client.util.swing.MessagePanel;
import nl.cloudfarming.client.util.swing.beanbinding.NonEmptyStringValidator;
import org.jdesktop.beansbinding.*;

/**
 * farm details panel bound to an existing {@link Farm}.
 *
 * @author johan & Merijn Zengers
 */
public class FarmDetailsEditPanel extends FarmDetailsPanel {

    protected JTextField farmIssuingAgencyTextField;
    private Farm farm;
    private ELProperty farmNameProperty = ELProperty.create("${text_ON_ACTION_OR_FOCUS_LOST}");
    private BeanProperty farmPropName = BeanProperty.create(Farm.PROP_NAME);
    private Binding farmNameBinding;
    private BindingGroup farmBindingGroup = new BindingGroup();
    private MessagePanel messagePanel;

    public FarmDetailsEditPanel(Farm farm) {
        super(new JTextField(), farm.getAddress());
        farmIssuingAgencyTextField = (JTextField) farmIssuingAgencyComponent;
        this.farm = farm;

        initComponents();
        bind();
        initValues();
    }

    private void initComponents() {
        // properties that affect the URIs of other entities in the project are immutable for now:
        farmIssuingAgencyTextField.setEditable(false);
        farmRegistrationNumberTextField.setEditable(false);

        messagePanel = new MessagePanel(MessagePanel.LARGE_ICON);
        this.add(messagePanel, "span");

    }

    /**
     * Bind the {@link FarmDetailsEditPanel#farmNameTextField} to {@link Farm#name}
     */
    private void bind() {
        farmNameBinding = Bindings.createAutoBinding(AutoBinding.UpdateStrategy.READ_WRITE,
                farm, farmPropName, farmNameTextField, farmNameProperty);
        farmNameBinding.setValidator(new NonEmptyStringValidator());
        farmBindingGroup.addBinding(farmNameBinding);
        farmBindingGroup.bind();
    }

    /**
     * Init the values of the fields
     */
    private void initValues() {
        setFarmName(farm.getName());
        setFarmIssuingAgency(farm.getIssuingAgency());
        setFarmRegistrationNumber(farm.getRegistrationNumber());
    }

    /**
     * Get the {@link Farm} who's properties are displayed on the panel
     * @return 
     */
    public Farm getFarm() {
        return farm;
    }

    /**
     * Get the {@link FarmDetailsEditPanel#messagePanel} which can display errors
     *
     * @return
     */
    public MessagePanel getErrorPanel() {
        return messagePanel;
    }

    /**
     * Get the {@link IssuingAgency} from this panel
     * @return 
     */
    @Override
    public IssuingAgency getFarmIssuingAgency() {
        return IssuingAgency.valueOf(farmIssuingAgencyTextField.getText().trim());
    }

    /**
     * Set the {@link IssuingAgency} for this panel
     * @param issuingAgency 
     */
    @Override
    public void setFarmIssuingAgency(IssuingAgency issuingAgency) {
        farmIssuingAgencyTextField.setText(issuingAgency.name());
    }
    
    
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy