net.sourceforge.msscodefactory.cfacc.v2_0.CFAccSwing.CFAccSwingContactAttrJPanel.java Source code

Java tutorial

Introduction

Here is the source code for net.sourceforge.msscodefactory.cfacc.v2_0.CFAccSwing.CFAccSwingContactAttrJPanel.java

Source

// Description: Java 7 Swing Attribute JPanel implementation for Contact.

/*
 *   MSS Code Factory Accounting Business Application Model
 *
 *   Copyright (c) 2014 Mark Sobkow
 *   
 *   This program is available as free software under the GNU GPL v3, or
 *   under a commercial license from Mark Sobkow.  For commercial licensing
 *   details, please contact msobkow@sasktel.net.
 *   
 *   Under the terms of the GPL:
 *   
 *      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/>.
 *   
 *      This source code incorporates modified modules originally licensed
 *      under the Apache 2.0 license by MSS Code Factory including CFSecurity
 *      (net-sourceforge-msscodefactory-2.0-cfsecurity.xml),
 *      CFInternet (net-sourceforge-msscodefactory-2.0-cfinternet.xml), and
 *      CFCrm 2.0 (net-sourceforge-msscodefactory-2.0-cfcrm.xml), with all of the
 *      required models being available as part of the MSS Code Factory 1.11
 *      distribution source and install zips.
 *   
 *      You can download installations of MSS Code Factory 1.11 from
 *      http://msscodefactory.sourceforge.net/
 *   
 * ***********************************************************************
 *
 *   Code manufactured by MSS Code Factory
 */

package net.sourceforge.msscodefactory.cfacc.v2_0.CFAccSwing;

import java.math.*;
import java.sql.*;
import java.text.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import net.sourceforge.msscodefactory.cflib.v1_11.CFLib.*;
import net.sourceforge.msscodefactory.cflib.v1_11.CFLib.Swing.*;
import org.apache.commons.codec.binary.Base64;
import net.sourceforge.msscodefactory.cfacc.v2_0.CFAcc.*;
import net.sourceforge.msscodefactory.cfacc.v2_0.CFAccObj.*;

/**
 *   CFAccSwingContactAttrJPanel Swing Attribute JPanel implementation
 *   for Contact.
 */
public class CFAccSwingContactAttrJPanel extends CFJPanel implements ICFAccSwingContactJPanelCommon {
    protected ICFAccSwingSchema swingSchema = null;
    boolean swingIsInitializing = true;

    protected class ContactTenantJLabel extends JLabel {
        public ContactTenantJLabel() {
            super();
            setText("Tenant");
        }
    }

    protected class CallbackContactTenantChosen implements ICFAccSwingTenantChosen {
        public CallbackContactTenantChosen() {
        }

        public void choseTenant(ICFAccTenantObj value) {
            Component cont = getParent();
            while ((cont != null) && (!(cont instanceof JInternalFrame))) {
                cont = cont.getParent();
            }
            if (cont != null) {
                if (!((JInternalFrame) cont).isClosed()) {
                    if (swingReferenceOwnerTenant != null) {
                        ICFAccContactObj cur = getSwingFocusAsContact();
                        if (cur != null) {
                            ICFAccContactEditObj editObj = (ICFAccContactEditObj) cur.getEdit();
                            if (null != editObj) {
                                CFJPanel.PanelMode curMode = getPanelMode();
                                if ((curMode == CFJPanel.PanelMode.Add) || (curMode == CFJPanel.PanelMode.Edit)) {
                                    swingReferenceOwnerTenant.setReferencedObject(value);
                                    editObj.setRequiredOwnerTenant(value);
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    protected class ActionViewContactTenantReference extends AbstractAction {
        public ActionViewContactTenantReference() {
            super();
            setEnabled(true);
        }

        public void actionPerformed(ActionEvent e) {
            final String S_ProcName = "actionPerformed";
            ICFAccContactObj focus = getSwingFocusAsContact();
            if (focus != null) {
                ICFAccContactEditObj editObj = (ICFAccContactEditObj) focus.getEdit();
                if (editObj != null) {
                    focus = editObj;
                }
                JInternalFrame frame = null;
                Container cont;
                JDesktopPane desktop;
                ICFAccTenantObj referencedObj = focus.getRequiredOwnerTenant(swingIsInitializing);
                if (referencedObj != null) {
                    String classCode = referencedObj.getClassCode();
                    if ("TENT".equals(classCode)) {
                        frame = swingSchema.getTenantFactory().newViewEditJInternalFrame(referencedObj);
                        cont = getParent();
                        while ((cont != null) && (!(cont instanceof JInternalFrame))) {
                            cont = cont.getParent();
                        }
                        if (cont != null) {
                            JInternalFrame myInternalFrame = (JInternalFrame) cont;
                            myInternalFrame.getDesktopPane().add(frame);
                            frame.setVisible(true);
                            frame.show();
                        }
                    } else {
                        throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(),
                                S_ProcName, "swingFocus", focus, "ICFAccTenantObj");
                    }
                }
            }
        }
    }

    protected class ActionPickContactTenantReference extends AbstractAction {
        public ActionPickContactTenantReference() {
            super();
            setEnabled(true);
        }

        public void actionPerformed(ActionEvent e) {
            final String S_ProcName = "actionPerformed";
            Container cont;
            JDesktopPane desktop;
            ICFAccSchemaObj schemaObj = swingSchema.getSchema();
            ICFAccContactObj focus = getSwingFocusAsContact();
            ICFAccContactEditObj editObj = (ICFAccContactEditObj) focus.getEdit();
            if (editObj != null) {
                focus = editObj;
            }
            ICFAccTenantObj referencedObj = focus.getRequiredOwnerTenant(swingIsInitializing);
            SortedMap<CFAccTenantPKey, ICFAccTenantObj> mapOfTenant = null;
            CFAccAuthorization auth = schemaObj.getAuthorization();
            long containingClusterId = auth.getSecClusterId();
            mapOfTenant = schemaObj.getTenantTableObj().readTenantByClusterIdx(containingClusterId);
            if (mapOfTenant == null) {
                throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                        "mapOfTenant");
            }
            Collection<ICFAccTenantObj> cltn = mapOfTenant.values();
            JInternalFrame frame = swingSchema.getTenantFactory().newPickerJInternalFrame(referencedObj, null, cltn,
                    new CallbackContactTenantChosen());
            ((ICFAccSwingTenantJPanelCommon) frame).setPanelMode(CFJPanel.PanelMode.View);
            cont = getParent();
            while ((cont != null) && (!(cont instanceof JInternalFrame))) {
                cont = cont.getParent();
            }
            if (cont != null) {
                JInternalFrame myInternalFrame = (JInternalFrame) cont;
                myInternalFrame.getDesktopPane().add(frame);
                frame.setVisible(true);
                frame.show();
            }
        }
    }

    protected class ContactTenantCFJReferenceEditor extends CFJReferenceEditor {
        public ContactTenantCFJReferenceEditor() {
            super(new ActionPickContactTenantReference(), new ActionViewContactTenantReference());
        }
    }

    protected class ContactListJLabel extends JLabel {
        public ContactListJLabel() {
            super();
            setText("Contact List");
        }
    }

    protected class CallbackContactListChosen implements ICFAccSwingContactListChosen {
        public CallbackContactListChosen() {
        }

        public void choseContactList(ICFAccContactListObj value) {
            Component cont = getParent();
            while ((cont != null) && (!(cont instanceof JInternalFrame))) {
                cont = cont.getParent();
            }
            if (cont != null) {
                if (!((JInternalFrame) cont).isClosed()) {
                    if (swingReferenceContainerContactList != null) {
                        ICFAccContactObj cur = getSwingFocusAsContact();
                        if (cur != null) {
                            ICFAccContactEditObj editObj = (ICFAccContactEditObj) cur.getEdit();
                            if (null != editObj) {
                                CFJPanel.PanelMode curMode = getPanelMode();
                                if ((curMode == CFJPanel.PanelMode.Add) || (curMode == CFJPanel.PanelMode.Edit)) {
                                    swingReferenceContainerContactList.setReferencedObject(value);
                                    editObj.setRequiredContainerContactList(value);
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    protected class ActionViewContactListReference extends AbstractAction {
        public ActionViewContactListReference() {
            super();
            setEnabled(true);
        }

        public void actionPerformed(ActionEvent e) {
            final String S_ProcName = "actionPerformed";
            ICFAccContactObj focus = getSwingFocusAsContact();
            if (focus != null) {
                ICFAccContactEditObj editObj = (ICFAccContactEditObj) focus.getEdit();
                if (editObj != null) {
                    focus = editObj;
                }
                JInternalFrame frame = null;
                Container cont;
                JDesktopPane desktop;
                ICFAccContactListObj referencedObj = focus.getRequiredContainerContactList(swingIsInitializing);
                if (referencedObj != null) {
                    String classCode = referencedObj.getClassCode();
                    if ("CTL".equals(classCode)) {
                        frame = swingSchema.getContactListFactory().newViewEditJInternalFrame(referencedObj);
                        cont = getParent();
                        while ((cont != null) && (!(cont instanceof JInternalFrame))) {
                            cont = cont.getParent();
                        }
                        if (cont != null) {
                            JInternalFrame myInternalFrame = (JInternalFrame) cont;
                            myInternalFrame.getDesktopPane().add(frame);
                            frame.setVisible(true);
                            frame.show();
                        }
                    } else {
                        throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(),
                                S_ProcName, "swingFocus", focus, "ICFAccContactListObj");
                    }
                }
            }
        }
    }

    protected class ActionPickContactListReference extends AbstractAction {
        public ActionPickContactListReference() {
            super();
            setEnabled(true);
        }

        public void actionPerformed(ActionEvent e) {
            final String S_ProcName = "actionPerformed";
            Container cont;
            JDesktopPane desktop;
            ICFAccSchemaObj schemaObj = swingSchema.getSchema();
            ICFAccContactObj focus = getSwingFocusAsContact();
            ICFAccContactEditObj editObj = (ICFAccContactEditObj) focus.getEdit();
            if (editObj != null) {
                focus = editObj;
            }
            ICFAccContactListObj referencedObj = focus.getRequiredContainerContactList(swingIsInitializing);
            SortedMap<CFAccContactListPKey, ICFAccContactListObj> mapOfContactList = null;
            CFAccAuthorization auth = schemaObj.getAuthorization();
            long containingTenantId = auth.getSecTenantId();
            mapOfContactList = schemaObj.getContactListTableObj().readContactListByTenantIdx(containingTenantId);
            if (mapOfContactList == null) {
                throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                        "mapOfContactList");
            }
            Collection<ICFAccContactListObj> cltn = mapOfContactList.values();
            JInternalFrame frame = swingSchema.getContactListFactory().newPickerJInternalFrame(referencedObj, null,
                    cltn, new CallbackContactListChosen());
            ((ICFAccSwingContactListJPanelCommon) frame).setPanelMode(CFJPanel.PanelMode.View);
            cont = getParent();
            while ((cont != null) && (!(cont instanceof JInternalFrame))) {
                cont = cont.getParent();
            }
            if (cont != null) {
                JInternalFrame myInternalFrame = (JInternalFrame) cont;
                myInternalFrame.getDesktopPane().add(frame);
                frame.setVisible(true);
                frame.show();
            }
        }
    }

    protected class ContactListCFJReferenceEditor extends CFJReferenceEditor {
        public ContactListCFJReferenceEditor() {
            super(new ActionPickContactListReference(), new ActionViewContactListReference());
        }
    }

    protected class ContactTimezoneJLabel extends JLabel {
        public ContactTimezoneJLabel() {
            super();
            setText("Contact Timezone");
        }
    }

    protected class CallbackContactTimezoneChosen implements ICFAccSwingISOTimezoneChosen {
        public CallbackContactTimezoneChosen() {
        }

        public void choseISOTimezone(ICFAccISOTimezoneObj value) {
            Component cont = getParent();
            while ((cont != null) && (!(cont instanceof JInternalFrame))) {
                cont = cont.getParent();
            }
            if (cont != null) {
                if (!((JInternalFrame) cont).isClosed()) {
                    if (swingReferenceLookupContactTimezone != null) {
                        ICFAccContactObj cur = getSwingFocusAsContact();
                        if (cur != null) {
                            ICFAccContactEditObj editObj = (ICFAccContactEditObj) cur.getEdit();
                            if (null != editObj) {
                                CFJPanel.PanelMode curMode = getPanelMode();
                                if ((curMode == CFJPanel.PanelMode.Add) || (curMode == CFJPanel.PanelMode.Edit)) {
                                    swingReferenceLookupContactTimezone.setReferencedObject(value);
                                    editObj.setOptionalLookupContactTimezone(value);
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    protected class ActionViewContactTimezoneReference extends AbstractAction {
        public ActionViewContactTimezoneReference() {
            super();
            setEnabled(true);
        }

        public void actionPerformed(ActionEvent e) {
            final String S_ProcName = "actionPerformed";
            ICFAccContactObj focus = getSwingFocusAsContact();
            if (focus != null) {
                ICFAccContactEditObj editObj = (ICFAccContactEditObj) focus.getEdit();
                if (editObj != null) {
                    focus = editObj;
                }
                JInternalFrame frame = null;
                Container cont;
                JDesktopPane desktop;
                ICFAccISOTimezoneObj referencedObj = focus.getOptionalLookupContactTimezone(swingIsInitializing);
                if (referencedObj != null) {
                    String classCode = referencedObj.getClassCode();
                    if ("ITZN".equals(classCode)) {
                        frame = swingSchema.getISOTimezoneFactory().newViewEditJInternalFrame(referencedObj);
                        cont = getParent();
                        while ((cont != null) && (!(cont instanceof JInternalFrame))) {
                            cont = cont.getParent();
                        }
                        if (cont != null) {
                            JInternalFrame myInternalFrame = (JInternalFrame) cont;
                            myInternalFrame.getDesktopPane().add(frame);
                            frame.setVisible(true);
                            frame.show();
                        }
                    } else {
                        throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(),
                                S_ProcName, "swingFocus", focus, "ICFAccISOTimezoneObj");
                    }
                }
            }
        }
    }

    protected class ActionPickContactTimezoneReference extends AbstractAction {
        public ActionPickContactTimezoneReference() {
            super();
            setEnabled(true);
        }

        public void actionPerformed(ActionEvent e) {
            final String S_ProcName = "actionPerformed";
            Container cont;
            JDesktopPane desktop;
            ICFAccSchemaObj schemaObj = swingSchema.getSchema();
            ICFAccContactObj focus = getSwingFocusAsContact();
            ICFAccContactEditObj editObj = (ICFAccContactEditObj) focus.getEdit();
            if (editObj != null) {
                focus = editObj;
            }
            ICFAccISOTimezoneObj referencedObj = focus.getOptionalLookupContactTimezone(swingIsInitializing);
            SortedMap<CFAccISOTimezonePKey, ICFAccISOTimezoneObj> mapOfISOTimezone = null;
            mapOfISOTimezone = schemaObj.getISOTimezoneTableObj().readAllISOTimezone();
            if (mapOfISOTimezone == null) {
                throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                        "mapOfISOTimezone");
            }
            Collection<ICFAccISOTimezoneObj> cltn = mapOfISOTimezone.values();
            JInternalFrame frame = swingSchema.getISOTimezoneFactory().newPickerJInternalFrame(referencedObj, null,
                    cltn, new CallbackContactTimezoneChosen());
            ((ICFAccSwingISOTimezoneJPanelCommon) frame).setPanelMode(CFJPanel.PanelMode.View);
            cont = getParent();
            while ((cont != null) && (!(cont instanceof JInternalFrame))) {
                cont = cont.getParent();
            }
            if (cont != null) {
                JInternalFrame myInternalFrame = (JInternalFrame) cont;
                myInternalFrame.getDesktopPane().add(frame);
                frame.setVisible(true);
                frame.show();
            }
        }
    }

    protected class ContactTimezoneCFJReferenceEditor extends CFJReferenceEditor {
        public ContactTimezoneCFJReferenceEditor() {
            super(new ActionPickContactTimezoneReference(), new ActionViewContactTimezoneReference());
        }
    }

    protected class ContactIdJLabel extends JLabel {
        public ContactIdJLabel() {
            super();
            setText("Contact Id");
        }
    }

    protected class ContactIdJEditor extends CFJInt64Editor {
        public ContactIdJEditor() {
            super();
            setMinValue(0L);
            setMaxValue(9223372036854775807L);
        }
    }

    protected class FullNameJLabel extends JLabel {
        public FullNameJLabel() {
            super();
            setText("Full Name");
        }
    }

    protected class FullNameJEditor extends CFJStringEditor {
        public FullNameJEditor() {
            super();
            setMaxLen(127);
        }
    }

    protected class LastNameJLabel extends JLabel {
        public LastNameJLabel() {
            super();
            setText("Last Name");
        }
    }

    protected class LastNameJEditor extends CFJStringEditor {
        public LastNameJEditor() {
            super();
            setMaxLen(50);
        }
    }

    protected class FirstNameJLabel extends JLabel {
        public FirstNameJLabel() {
            super();
            setText("First Name");
        }
    }

    protected class FirstNameJEditor extends CFJStringEditor {
        public FirstNameJEditor() {
            super();
            setMaxLen(50);
        }
    }

    protected class CustomJLabel extends JLabel {
        public CustomJLabel() {
            super();
            setText("Custom 1");
        }
    }

    protected class CustomJEditor extends CFJStringEditor {
        public CustomJEditor() {
            super();
            setMaxLen(254);
        }
    }

    protected class Custom2JLabel extends JLabel {
        public Custom2JLabel() {
            super();
            setText("Custom 2");
        }
    }

    protected class Custom2JEditor extends CFJStringEditor {
        public Custom2JEditor() {
            super();
            setMaxLen(254);
        }
    }

    protected class Custom3JLabel extends JLabel {
        public Custom3JLabel() {
            super();
            setText("Custom 3");
        }
    }

    protected class Custom3JEditor extends CFJStringEditor {
        public Custom3JEditor() {
            super();
            setMaxLen(254);
        }
    }

    protected ICFAccTenantObj swingOwnerTenantObj = null;
    protected ContactTenantJLabel swingLabelOwnerTenant = null;
    protected ContactTenantCFJReferenceEditor swingReferenceOwnerTenant = null;
    protected ICFAccContactListObj swingContainerContactListObj = null;
    protected ContactListJLabel swingLabelContainerContactList = null;
    protected ContactListCFJReferenceEditor swingReferenceContainerContactList = null;
    protected ICFAccISOTimezoneObj swingLookupContactTimezoneObj = null;
    protected ContactTimezoneJLabel swingLabelLookupContactTimezone = null;
    protected ContactTimezoneCFJReferenceEditor swingReferenceLookupContactTimezone = null;
    protected ContactIdJLabel swingLabelContactId = null;
    protected ContactIdJEditor swingEditorContactId = null;
    protected FullNameJLabel swingLabelFullName = null;
    protected FullNameJEditor swingEditorFullName = null;
    protected LastNameJLabel swingLabelLastName = null;
    protected LastNameJEditor swingEditorLastName = null;
    protected FirstNameJLabel swingLabelFirstName = null;
    protected FirstNameJEditor swingEditorFirstName = null;
    protected CustomJLabel swingLabelCustom = null;
    protected CustomJEditor swingEditorCustom = null;
    protected Custom2JLabel swingLabelCustom2 = null;
    protected Custom2JEditor swingEditorCustom2 = null;
    protected Custom3JLabel swingLabelCustom3 = null;
    protected Custom3JEditor swingEditorCustom3 = null;

    public CFAccSwingContactAttrJPanel(ICFAccSwingSchema argSchema, ICFAccContactObj argFocus) {
        super();
        JLabel label;
        JComponent compo;
        CFJReferenceEditor reference;
        final String S_ProcName = "construct-schema-focus";
        if (argSchema == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 1,
                    "argSchema");
        }
        // argFocus is optional; focus may be set later during execution as
        // conditions of the runtime change.
        swingSchema = argSchema;
        setSwingFocusAsContact(argFocus);
        final int spacing = 5;
        int y = spacing;
        final int height = 25;
        final int textheight = 80;
        final int vspacing = height + spacing;
        final int textvspacing = textheight + spacing;
        final int labelx = spacing;
        final int labelwidth = 200;
        final int fieldx = labelx + labelwidth + spacing;
        final int fieldwidth = 785;
        final int panelwidth = fieldx + fieldwidth + spacing;
        // temporary -- I think you have to have a panel bigger than the coordinates initially
        setSize(panelwidth, 100000);

        label = getSwingLabelOwnerTenant();
        add(label);
        label.setBounds(labelx, y, labelwidth, height);
        reference = getSwingReferenceOwnerTenant();
        add(reference);
        reference.setBounds(fieldx, y, fieldwidth, height);
        y = y + vspacing;

        label = getSwingLabelContainerContactList();
        add(label);
        label.setBounds(labelx, y, labelwidth, height);
        reference = getSwingReferenceContainerContactList();
        add(reference);
        reference.setBounds(fieldx, y, fieldwidth, height);
        y = y + vspacing;

        label = getSwingLabelLookupContactTimezone();
        add(label);
        label.setBounds(labelx, y, labelwidth, height);
        reference = getSwingReferenceLookupContactTimezone();
        add(reference);
        reference.setBounds(fieldx, y, fieldwidth, height);
        y = y + vspacing;

        label = getSwingLabelContactId();
        add(label);
        label.setBounds(labelx, y, labelwidth, height);
        compo = getSwingEditorContactId();
        add(compo);
        compo.setBounds(fieldx, y, fieldwidth, height);
        y = y + vspacing;

        label = getSwingLabelFullName();
        add(label);
        label.setBounds(labelx, y, labelwidth, height);
        compo = getSwingEditorFullName();
        add(compo);
        compo.setBounds(fieldx, y, fieldwidth, height);
        y = y + vspacing;

        label = getSwingLabelLastName();
        add(label);
        label.setBounds(labelx, y, labelwidth, height);
        compo = getSwingEditorLastName();
        add(compo);
        compo.setBounds(fieldx, y, fieldwidth, height);
        y = y + vspacing;

        label = getSwingLabelFirstName();
        add(label);
        label.setBounds(labelx, y, labelwidth, height);
        compo = getSwingEditorFirstName();
        add(compo);
        compo.setBounds(fieldx, y, fieldwidth, height);
        y = y + vspacing;

        label = getSwingLabelCustom();
        add(label);
        label.setBounds(labelx, y, labelwidth, height);
        compo = getSwingEditorCustom();
        add(compo);
        compo.setBounds(fieldx, y, fieldwidth, height);
        y = y + vspacing;

        label = getSwingLabelCustom2();
        add(label);
        label.setBounds(labelx, y, labelwidth, height);
        compo = getSwingEditorCustom2();
        add(compo);
        compo.setBounds(fieldx, y, fieldwidth, height);
        y = y + vspacing;

        label = getSwingLabelCustom3();
        add(label);
        label.setBounds(labelx, y, labelwidth, height);
        compo = getSwingEditorCustom3();
        add(compo);
        compo.setBounds(fieldx, y, fieldwidth, height);
        y = y + vspacing;

        // Now we can set the proper size based on the fields and references populated
        setSize(panelwidth, y);
        Dimension pfsz = new Dimension(panelwidth, y);
        setPreferredSize(pfsz);
        Dimension min = new Dimension(400, y);
        setMinimumSize(min);
        populateFields();
        adjustComponentEnableStates();
        swingIsInitializing = false;
    }

    public ICFAccSwingSchema getSwingSchema() {
        return (swingSchema);
    }

    public void setSwingFocus(ICFLibAnyObj2 value) {
        final String S_ProcName = "setSwingFocus";
        if ((value == null) || (value instanceof ICFAccContactObj)) {
            super.setSwingFocus(value);
        } else {
            throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName, "value",
                    value, "ICFAccContactObj");
        }
        populateFields();
        adjustComponentEnableStates();
    }

    public ICFAccContactObj getSwingFocusAsContact() {
        return ((ICFAccContactObj) getSwingFocus());
    }

    public void setSwingFocusAsContact(ICFAccContactObj value) {
        setSwingFocus(value);
    }

    public ICFAccTenantObj getSwingOwnerTenantObj() {
        return (swingOwnerTenantObj);
    }

    public void setSwingOwnerTenantObj(ICFAccTenantObj value) {
        swingOwnerTenantObj = value;
    }

    public ContactTenantJLabel getSwingLabelOwnerTenant() {
        if (swingLabelOwnerTenant == null) {
            swingLabelOwnerTenant = new ContactTenantJLabel();
        }
        return (swingLabelOwnerTenant);
    }

    public CFJReferenceEditor getSwingReferenceOwnerTenant() {
        if (swingReferenceOwnerTenant == null) {
            swingReferenceOwnerTenant = new ContactTenantCFJReferenceEditor();
        }
        return (swingReferenceOwnerTenant);
    }

    public void setSwingReferenceOwnerTenant(ContactTenantCFJReferenceEditor value) {
        swingReferenceOwnerTenant = value;
    }

    public ICFAccContactListObj getSwingContainerContactListObj() {
        if (swingContainerContactListObj == null) {
        }
        return (swingContainerContactListObj);
    }

    public void setSwingContainerContactListObj(ICFAccContactListObj value) {
        swingContainerContactListObj = value;
    }

    public ContactListJLabel getSwingLabelContainerContactList() {
        if (swingLabelContainerContactList == null) {
            swingLabelContainerContactList = new ContactListJLabel();
        }
        return (swingLabelContainerContactList);
    }

    public ContactListCFJReferenceEditor getSwingReferenceContainerContactList() {
        if (swingReferenceContainerContactList == null) {
            swingReferenceContainerContactList = new ContactListCFJReferenceEditor();
        }
        return (swingReferenceContainerContactList);
    }

    public void setSwingReferenceContainerContactList(ContactListCFJReferenceEditor value) {
        swingReferenceContainerContactList = value;
    }

    public ICFAccISOTimezoneObj getSwingLookupContactTimezoneObj() {
        return (swingLookupContactTimezoneObj);
    }

    public void setSwingLookupContactTimezoneObj(ICFAccISOTimezoneObj value) {
        swingLookupContactTimezoneObj = value;
    }

    public JLabel getSwingLabelLookupContactTimezone() {
        if (swingLabelLookupContactTimezone == null) {
            swingLabelLookupContactTimezone = new ContactTimezoneJLabel();
        }
        return (swingLabelLookupContactTimezone);
    }

    public CFJReferenceEditor getSwingReferenceLookupContactTimezone() {
        if (swingReferenceLookupContactTimezone == null) {
            swingReferenceLookupContactTimezone = new ContactTimezoneCFJReferenceEditor();
        }
        return (swingReferenceLookupContactTimezone);
    }

    public void setSwingReferenceLookupContactTimezone(ContactTimezoneCFJReferenceEditor value) {
        swingReferenceLookupContactTimezone = value;
    }

    public ContactIdJLabel getSwingLabelContactId() {
        if (swingLabelContactId == null) {
            swingLabelContactId = new ContactIdJLabel();
        }
        return (swingLabelContactId);
    }

    public void setSwingLabelContactId(ContactIdJLabel value) {
        swingLabelContactId = value;
    }

    public ContactIdJEditor getSwingEditorContactId() {
        if (swingEditorContactId == null) {
            swingEditorContactId = new ContactIdJEditor();
        }
        return (swingEditorContactId);
    }

    public void setSwingEditorContactId(ContactIdJEditor value) {
        swingEditorContactId = value;
    }

    public FullNameJLabel getSwingLabelFullName() {
        if (swingLabelFullName == null) {
            swingLabelFullName = new FullNameJLabel();
        }
        return (swingLabelFullName);
    }

    public void setSwingLabelFullName(FullNameJLabel value) {
        swingLabelFullName = value;
    }

    public FullNameJEditor getSwingEditorFullName() {
        if (swingEditorFullName == null) {
            swingEditorFullName = new FullNameJEditor();
        }
        return (swingEditorFullName);
    }

    public void setSwingEditorFullName(FullNameJEditor value) {
        swingEditorFullName = value;
    }

    public LastNameJLabel getSwingLabelLastName() {
        if (swingLabelLastName == null) {
            swingLabelLastName = new LastNameJLabel();
        }
        return (swingLabelLastName);
    }

    public void setSwingLabelLastName(LastNameJLabel value) {
        swingLabelLastName = value;
    }

    public LastNameJEditor getSwingEditorLastName() {
        if (swingEditorLastName == null) {
            swingEditorLastName = new LastNameJEditor();
        }
        return (swingEditorLastName);
    }

    public void setSwingEditorLastName(LastNameJEditor value) {
        swingEditorLastName = value;
    }

    public FirstNameJLabel getSwingLabelFirstName() {
        if (swingLabelFirstName == null) {
            swingLabelFirstName = new FirstNameJLabel();
        }
        return (swingLabelFirstName);
    }

    public void setSwingLabelFirstName(FirstNameJLabel value) {
        swingLabelFirstName = value;
    }

    public FirstNameJEditor getSwingEditorFirstName() {
        if (swingEditorFirstName == null) {
            swingEditorFirstName = new FirstNameJEditor();
        }
        return (swingEditorFirstName);
    }

    public void setSwingEditorFirstName(FirstNameJEditor value) {
        swingEditorFirstName = value;
    }

    public CustomJLabel getSwingLabelCustom() {
        if (swingLabelCustom == null) {
            swingLabelCustom = new CustomJLabel();
        }
        return (swingLabelCustom);
    }

    public void setSwingLabelCustom(CustomJLabel value) {
        swingLabelCustom = value;
    }

    public CustomJEditor getSwingEditorCustom() {
        if (swingEditorCustom == null) {
            swingEditorCustom = new CustomJEditor();
        }
        return (swingEditorCustom);
    }

    public void setSwingEditorCustom(CustomJEditor value) {
        swingEditorCustom = value;
    }

    public Custom2JLabel getSwingLabelCustom2() {
        if (swingLabelCustom2 == null) {
            swingLabelCustom2 = new Custom2JLabel();
        }
        return (swingLabelCustom2);
    }

    public void setSwingLabelCustom2(Custom2JLabel value) {
        swingLabelCustom2 = value;
    }

    public Custom2JEditor getSwingEditorCustom2() {
        if (swingEditorCustom2 == null) {
            swingEditorCustom2 = new Custom2JEditor();
        }
        return (swingEditorCustom2);
    }

    public void setSwingEditorCustom2(Custom2JEditor value) {
        swingEditorCustom2 = value;
    }

    public Custom3JLabel getSwingLabelCustom3() {
        if (swingLabelCustom3 == null) {
            swingLabelCustom3 = new Custom3JLabel();
        }
        return (swingLabelCustom3);
    }

    public void setSwingLabelCustom3(Custom3JLabel value) {
        swingLabelCustom3 = value;
    }

    public Custom3JEditor getSwingEditorCustom3() {
        if (swingEditorCustom3 == null) {
            swingEditorCustom3 = new Custom3JEditor();
        }
        return (swingEditorCustom3);
    }

    public void setSwingEditorCustom3(Custom3JEditor value) {
        swingEditorCustom3 = value;
    }

    public void doLayout() {
        JLabel label;
        JComponent compo;
        CFJReferenceEditor reference;
        Dimension dim;
        final int spacing = 5;
        int y = spacing;
        final int height = 25;
        final int textheight = 80;
        final int vspacing = height + spacing;
        final int textvspacing = textheight + spacing;
        final int labelx = spacing;
        final int labelwidth = 200;
        final int fieldx = labelx + labelwidth + spacing;
        final int fieldwidth = 1024;
        Dimension jpsz = getSize();
        int usefieldwidth = jpsz.width - 215;

        label = getSwingLabelOwnerTenant();
        label.setBounds(labelx, y, labelwidth, height);
        reference = getSwingReferenceOwnerTenant();
        reference.setBounds(fieldx, y, usefieldwidth, height);
        y = y + vspacing;

        label = getSwingLabelContainerContactList();
        label.setBounds(labelx, y, labelwidth, height);
        reference = getSwingReferenceContainerContactList();
        reference.setBounds(fieldx, y, usefieldwidth, height);
        y = y + vspacing;

        label = getSwingLabelLookupContactTimezone();
        label.setBounds(labelx, y, labelwidth, height);
        reference = getSwingReferenceLookupContactTimezone();
        reference.setBounds(fieldx, y, usefieldwidth, height);
        y = y + vspacing;

        label = getSwingLabelContactId();
        label.setBounds(labelx, y, labelwidth, height);
        compo = getSwingEditorContactId();
        dim = compo.getMaximumSize();
        if (dim.width < usefieldwidth) {
            compo.setBounds(fieldx, y, dim.width, height);
        } else {
            compo.setBounds(fieldx, y, fieldwidth, height);
        }
        y = y + vspacing;

        label = getSwingLabelFullName();
        label.setBounds(labelx, y, labelwidth, height);
        compo = getSwingEditorFullName();
        dim = compo.getMaximumSize();
        if (dim.width < usefieldwidth) {
            compo.setBounds(fieldx, y, dim.width, height);
        } else {
            compo.setBounds(fieldx, y, fieldwidth, height);
        }
        y = y + vspacing;

        label = getSwingLabelLastName();
        label.setBounds(labelx, y, labelwidth, height);
        compo = getSwingEditorLastName();
        dim = compo.getMaximumSize();
        if (dim.width < usefieldwidth) {
            compo.setBounds(fieldx, y, dim.width, height);
        } else {
            compo.setBounds(fieldx, y, fieldwidth, height);
        }
        y = y + vspacing;

        label = getSwingLabelFirstName();
        label.setBounds(labelx, y, labelwidth, height);
        compo = getSwingEditorFirstName();
        dim = compo.getMaximumSize();
        if (dim.width < usefieldwidth) {
            compo.setBounds(fieldx, y, dim.width, height);
        } else {
            compo.setBounds(fieldx, y, fieldwidth, height);
        }
        y = y + vspacing;

        label = getSwingLabelCustom();
        label.setBounds(labelx, y, labelwidth, height);
        compo = getSwingEditorCustom();
        dim = compo.getMaximumSize();
        if (dim.width < usefieldwidth) {
            compo.setBounds(fieldx, y, dim.width, height);
        } else {
            compo.setBounds(fieldx, y, fieldwidth, height);
        }
        y = y + vspacing;

        label = getSwingLabelCustom2();
        label.setBounds(labelx, y, labelwidth, height);
        compo = getSwingEditorCustom2();
        dim = compo.getMaximumSize();
        if (dim.width < usefieldwidth) {
            compo.setBounds(fieldx, y, dim.width, height);
        } else {
            compo.setBounds(fieldx, y, fieldwidth, height);
        }
        y = y + vspacing;

        label = getSwingLabelCustom3();
        label.setBounds(labelx, y, labelwidth, height);
        compo = getSwingEditorCustom3();
        dim = compo.getMaximumSize();
        if (dim.width < usefieldwidth) {
            compo.setBounds(fieldx, y, dim.width, height);
        } else {
            compo.setBounds(fieldx, y, fieldwidth, height);
        }
        y = y + vspacing;

    }

    public void populateFields() {
        ICFAccContactObj popObj;
        ICFAccContactObj focus = getSwingFocusAsContact();
        if (focus != null) {
            popObj = (ICFAccContactObj) (focus.getEdit());
            if (popObj == null) {
                popObj = focus;
            }
        } else {
            popObj = null;
        }
        if (getPanelMode() == CFJPanel.PanelMode.Unknown) {
            popObj = null;
        }
        if (popObj == null) {
            swingOwnerTenantObj = null;
        } else {
            swingOwnerTenantObj = popObj.getRequiredOwnerTenant(swingIsInitializing);
        }
        if (swingReferenceOwnerTenant != null) {
            swingReferenceOwnerTenant.setReferencedObject(swingOwnerTenantObj);
        }

        if (popObj == null) {
            swingContainerContactListObj = null;
        } else {
            swingContainerContactListObj = popObj.getRequiredContainerContactList(swingIsInitializing);
        }
        if (swingReferenceContainerContactList != null) {
            swingReferenceContainerContactList.setReferencedObject(swingContainerContactListObj);
        }

        if (popObj == null) {
            swingLookupContactTimezoneObj = null;
        } else {
            swingLookupContactTimezoneObj = popObj.getOptionalLookupContactTimezone(swingIsInitializing);
        }
        if (swingReferenceLookupContactTimezone != null) {
            swingReferenceLookupContactTimezone.setReferencedObject(swingLookupContactTimezoneObj);
        }

        if (popObj == null) {
            getSwingEditorContactId().setInt64Value(null);
        } else {
            getSwingEditorContactId().setInt64Value(popObj.getRequiredContactId());
        }

        if (popObj == null) {
            getSwingEditorFullName().setStringValue(null);
        } else {
            getSwingEditorFullName().setStringValue(popObj.getRequiredFullName());
        }

        if (popObj == null) {
            getSwingEditorLastName().setStringValue(null);
        } else {
            getSwingEditorLastName().setStringValue(popObj.getOptionalLastName());
        }

        if (popObj == null) {
            getSwingEditorFirstName().setStringValue(null);
        } else {
            getSwingEditorFirstName().setStringValue(popObj.getOptionalFirstName());
        }

        if (popObj == null) {
            getSwingEditorCustom().setStringValue(null);
        } else {
            getSwingEditorCustom().setStringValue(popObj.getOptionalCustom());
        }

        if (popObj == null) {
            getSwingEditorCustom2().setStringValue(null);
        } else {
            getSwingEditorCustom2().setStringValue(popObj.getOptionalCustom2());
        }

        if (popObj == null) {
            getSwingEditorCustom3().setStringValue(null);
        } else {
            getSwingEditorCustom3().setStringValue(popObj.getOptionalCustom3());
        }
    }

    public void postFields() {
        final String S_ProcName = "postFields";
        ICFAccContactObj focus = getSwingFocusAsContact();
        ICFAccContactEditObj editObj;
        if (focus != null) {
            editObj = (ICFAccContactEditObj) (focus.getEdit());
        } else {
            editObj = null;
        }
        if (editObj == null) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "Panel is unfocused or is not editing the focus object");
        }
        // You are not allowed to edit the Container or Owner references, so they're not retrieved

        swingLookupContactTimezoneObj = (ICFAccISOTimezoneObj) (swingReferenceLookupContactTimezone
                .getReferencedObject());
        editObj.setOptionalLookupContactTimezone(swingLookupContactTimezoneObj);

        editObj.setRequiredFullName(getSwingEditorFullName().getStringValue());

        editObj.setOptionalLastName(getSwingEditorLastName().getStringValue());

        editObj.setOptionalFirstName(getSwingEditorFirstName().getStringValue());

        editObj.setOptionalCustom(getSwingEditorCustom().getStringValue());

        editObj.setOptionalCustom2(getSwingEditorCustom2().getStringValue());

        editObj.setOptionalCustom3(getSwingEditorCustom3().getStringValue());
    }

    public void setPanelMode(CFJPanel.PanelMode value) {
        final String S_ProcName = "setPanelMode";
        CFJPanel.PanelMode oldValue = getPanelMode();
        if (oldValue == value) {
            return;
        }
        ICFAccContactObj focus = getSwingFocusAsContact();
        if ((value != CFJPanel.PanelMode.Unknown) && (value != CFJPanel.PanelMode.View)) {
            if (focus == null) {
                throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                        "swingFocus");
            }
        }
        ICFAccContactEditObj editObj;
        if (focus != null) {
            editObj = (ICFAccContactEditObj) focus.getEdit();
        } else {
            editObj = null;
        }
        switch (value) {
        case Unknown:
            switch (oldValue) {
            case Unknown:
                break;
            default:
                if (editObj != null) {
                    editObj.endEdit();
                }
                break;
            }
            break;
        case Add:
            switch (oldValue) {
            case Unknown:
            case Add:
            case View:
                if (editObj == null) {
                    if (focus != null) {
                        if (!focus.getIsNew()) {
                            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                                    "Transitioning to PanelMode Add requires Focus.getIsNew() to be true");
                        }
                        editObj = (ICFAccContactEditObj) focus.beginEdit();
                        if (editObj == null) {
                            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                                    "Expected beginEdit() to return a new edition of the focus object");
                        }
                    } else {
                        throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                                "focus");
                    }
                }
                break;
            case Edit:
                throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                        "Cannot transition PanelMode Edit to Add");
            case Update:
                throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                        "Cannot transition PanelMode Update to Add");
            case Delete:
                throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                        "Cannot transition PanelMode Delete to Add");
            default:
                throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                        "Cannot transition PanelMode default to Add");
            }
            break;
        case View:
            switch (oldValue) {
            case Unknown:
                break;
            case View:
                break;
            case Edit:
                break;
            case Update:
                break;
            case Delete:
                break;
            default:
                throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                        "Cannot transition PanelMode " + oldValue + " to View");
            }
            if (editObj != null) {
                editObj.endEdit();
            }
            break;
        case Edit:
            switch (oldValue) {
            case Unknown:
                if (editObj == null) {
                    editObj = (ICFAccContactEditObj) focus.beginEdit();
                    if (editObj == null) {
                        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                                "Expected beginEdit() to return a new edition of the focus object");
                    }
                }
                break;
            case View:
                if (editObj == null) {
                    editObj = (ICFAccContactEditObj) focus.beginEdit();
                    if (editObj == null) {
                        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                                "Expected beginEdit() to return a new edition of the focus object");
                    }
                }
                break;
            case Edit:
                if (editObj == null) {
                    editObj = (ICFAccContactEditObj) focus.beginEdit();
                    if (editObj == null) {
                        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                                "Expected beginEdit() to return a new edition of the focus object");
                    }
                }
                break;
            default:
                throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                        "Cannot transition PanelMode " + oldValue + " to Edit");
            }
            break;
        case Update:
            if ((oldValue != CFJPanel.PanelMode.Edit) && (oldValue != CFJPanel.PanelMode.Add)) {
                throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                        "Cannot transition from mode " + oldValue + " to Update");
            }
            super.setPanelMode(value);
            if (editObj != null) {
                postFields();
                if (editObj.getIsNew()) {
                    focus = (ICFAccContactObj) editObj.create();
                    setSwingFocus(focus);
                } else {
                    editObj.update();
                }
                editObj.endEdit();
                editObj = null;
            }
            setPanelMode(CFJPanel.PanelMode.View);
            break;
        case Delete:
            switch (oldValue) {
            case View:
                if (focus != null) {
                    if (editObj == null) {
                        editObj = (ICFAccContactEditObj) focus.beginEdit();
                        if (editObj == null) {
                            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                                    "Expected beginEdit() to return a new edition of the focus object");
                        }
                    }
                }
                break;
            case Edit:
                if (focus != null) {
                    if (editObj == null) {
                        editObj = (ICFAccContactEditObj) focus.beginEdit();
                        if (editObj == null) {
                            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                                    "Expected beginEdit() to return a new edition of the focus object");
                        }
                    }
                }
                break;
            case Update:
                throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                        "Cannot transition PanelMode Update to Delete");
            case Delete:
                if (editObj == null) {
                    editObj = (ICFAccContactEditObj) focus.beginEdit();
                    if (editObj == null) {
                        throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                                "Expected beginEdit() to return a new edition of the focus object");
                    }
                }
                break;
            default:
                throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                        "Cannot transition PanelMode " + oldValue + " to Delete");
            }
            editObj.delete();
            editObj.endEdit();
            setSwingFocus(null);
            setPanelMode(CFJPanel.PanelMode.Unknown);
            break;
        default:
            switch (oldValue) {
            case Unknown:
                break;
            default:
                if (editObj != null) {
                    editObj.endEdit();
                }
                break;
            }
            break;
        }
        super.setPanelMode(value);
        populateFields();
        adjustComponentEnableStates();
    }

    public void adjustComponentEnableStates() {
        CFJPanel.PanelMode mode = getPanelMode();
        boolean isEditing;
        switch (mode) {
        case Unknown:
        case View:
        case Delete:
            isEditing = false;
            break;
        case Add:
        case Edit:
        case Update:
            isEditing = true;
            break;
        default:
            isEditing = false;
            break;
        }
        if (isEditing) {
            ICFAccContactObj focus = getSwingFocusAsContact();
            if (focus == null) {
                isEditing = false;
            } else if (null == focus.getEdit()) {
                isEditing = false;
            }
        }
        if (swingReferenceOwnerTenant != null) {
            swingReferenceOwnerTenant.setEnabled(false);
        }
        if (swingReferenceContainerContactList != null) {
            swingReferenceContainerContactList.setEnabled(false);
        }
        if (swingReferenceLookupContactTimezone != null) {
            swingReferenceLookupContactTimezone.setEnabled(isEditing);
        }
        if (swingEditorContactId != null) {
            swingEditorContactId.setEnabled(false);
        }
        if (swingEditorFullName != null) {
            swingEditorFullName.setEnabled(isEditing);
        }
        if (swingEditorLastName != null) {
            swingEditorLastName.setEnabled(isEditing);
        }
        if (swingEditorFirstName != null) {
            swingEditorFirstName.setEnabled(isEditing);
        }
        if (swingEditorCustom != null) {
            swingEditorCustom.setEnabled(isEditing);
        }
        if (swingEditorCustom2 != null) {
            swingEditorCustom2.setEnabled(isEditing);
        }
        if (swingEditorCustom3 != null) {
            swingEditorCustom3.setEnabled(isEditing);
        }
    }
}