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

Java tutorial

Introduction

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

Source

// Description: Java 7 Swing View/Edit JInternalFrame implementation for AccountConfig.

/*
 *   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.*;

/**
 *   CFAccSwingAccountConfigViewEditJInternalFrame Swing View/Edit JInternalFrame implementation
 *   for AccountConfig.
 */
public class CFAccSwingAccountConfigViewEditJInternalFrame extends CFJInternalFrame
        implements ICFAccSwingAccountConfigJPanelCommon {
    protected ICFAccSwingSchema swingSchema = null;
    protected JPanel swingViewEditJPanel = null;

    protected class ActionEdit extends AbstractAction {
        public ActionEdit() {
            super();
            putValue(Action.NAME, "Edit AccountConfig");
            setEnabled(true);
        }

        public void actionPerformed(ActionEvent e) {
            final String S_ProcName = "actionPerformed";
            if (getSwingFocusAsAccountConfig() != null) {
                if (null == getSwingFocusAsAccountConfig().getEdit()) {
                    setPanelMode(CFJPanel.PanelMode.Edit);
                } else {
                    throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                            "Cannot begin an edit of an object already edited by another window instance");
                }
            }
        }
    }

    protected class ActionSave extends AbstractAction {
        public ActionSave() {
            super();
            putValue(Action.NAME, "Save and Close");
            setEnabled(true);
        }

        public void actionPerformed(ActionEvent e) {
            final String S_ProcName = "actionPerformed";
            ICFAccAccountConfigObj focus = getSwingFocusAsAccountConfig();
            if (focus != null) {
                ICFAccAccountConfigEditObj editObj = (ICFAccAccountConfigEditObj) (focus.getEdit());
                if (editObj != null) {
                    setPanelMode(CFJPanel.PanelMode.Update);
                } else {
                    throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                            "Cannot save on object that isn't being edited");
                }
            }
            try {
                setClosed(true);
            } catch (Exception x) {
            }
        }
    }

    protected class ActionDelete extends AbstractAction {
        public ActionDelete() {
            super();
            putValue(Action.NAME, "Delete AccountConfig...");
            setEnabled(true);
        }

        public void actionPerformed(ActionEvent e) {
            final String S_ProcName = "actionPerformed";
            if (getSwingFocusAsAccountConfig() != null) {
                if (null == getSwingFocusAsAccountConfig().getEdit()) {
                    JInternalFrame frame = swingSchema.getAccountConfigFactory()
                            .newAskDeleteJInternalFrame(getSwingFocusAsAccountConfig());
                    ((ICFAccSwingAccountConfigJPanelCommon) frame).setPanelMode(CFJPanel.PanelMode.View);
                    getDesktopPane().add(frame);
                    frame.setVisible(true);
                    frame.show();
                } else {
                    throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                            "Cannot begin deletion of an object already edited by another window instance");
                }
            }
        }
    }

    protected class ActionClose extends AbstractAction {
        public ActionClose() {
            super();
            putValue(Action.NAME, "Close/Cancel");
            setEnabled(true);
        }

        public void actionPerformed(ActionEvent e) {
            ICFAccAccountConfigObj focus = getSwingFocusAsAccountConfig();
            if (focus != null) {
                ICFAccAccountConfigEditObj editObj = (ICFAccAccountConfigEditObj) focus.getEdit();
                if (editObj != null) {
                    if (editObj.getIsNew()) {
                        editObj.endEdit();
                        setSwingFocus(null);
                        setPanelMode(CFJPanel.PanelMode.Unknown);
                    } else {
                        editObj.endEdit();
                        setPanelMode(CFJPanel.PanelMode.View);
                    }
                }
            }
            try {
                setClosed(true);
            } catch (Exception x) {
            }
        }
    }

    protected Action actionEdit = null;
    protected Action actionSave = null;
    protected Action actionDelete = null;
    protected Action actionClose = null;
    protected JMenuBar frameMenuBar = null;
    protected JMenu menuFile = null;

    public CFAccSwingAccountConfigViewEditJInternalFrame(ICFAccSwingSchema argSchema,
            ICFAccAccountConfigObj argFocus) {
        super();
        final String S_ProcName = "construct-schema-focus";
        if (argSchema == null) {
            throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 1,
                    "argSchema");
        }
        setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        // argFocus is optional; focus may be set later during execution as
        // conditions of the runtime change.
        swingSchema = argSchema;
        swingFocus = argFocus;
        if ((argFocus != null) && (!argFocus.getIsNew())) {
            argFocus = (ICFAccAccountConfigObj) argFocus.read(true);
            swingFocus = argFocus;
        }
        swingViewEditJPanel = argSchema.getAccountConfigFactory().newViewEditJPanel(argFocus);
        setContentPane(swingViewEditJPanel);
        Dimension dim = new Dimension(1024, 480);
        setSize(dim);
        dim = new Dimension(320, 240);
        setMinimumSize(dim);
        setTitle("View/Edit AccountConfig");
        setJMenuBar(getFrameMenuBar());
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        setClosable(false);
    }

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

    public void setSwingFocus(ICFLibAnyObj2 value) {
        final String S_ProcName = "setSwingFocus";
        if ((value == null) || (value instanceof ICFAccAccountConfigObj)) {
            super.setSwingFocus(value);
        } else {
            throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName, "value",
                    value, "ICFAccAccountConfigObj");
        }
        ((ICFAccSwingAccountConfigJPanelCommon) swingViewEditJPanel).setSwingFocus(value);
        ICFAccAccountConfigObj argFocus = (ICFAccAccountConfigObj) value;
        if ((argFocus != null) && (!argFocus.getIsNew())) {
            argFocus = (ICFAccAccountConfigObj) argFocus.read(true);
            super.setSwingFocus(argFocus);
        }
    }

    public ICFAccAccountConfigObj getSwingFocusAsAccountConfig() {
        return ((ICFAccAccountConfigObj) getSwingFocus());
    }

    public void setSwingFocusAsAccountConfig(ICFAccAccountConfigObj value) {
        setSwingFocus(value);
    }

    public JMenuBar getFrameMenuBar() {
        if (frameMenuBar == null) {
            JMenuItem menuItem;
            frameMenuBar = new JMenuBar();
            menuFile = new JMenu("File");
            actionEdit = new ActionEdit();
            menuItem = new JMenuItem(actionEdit);
            menuFile.add(menuItem);
            actionSave = new ActionSave();
            menuItem = new JMenuItem(actionSave);
            menuFile.add(menuItem);
            actionClose = new ActionClose();
            menuItem = new JMenuItem(actionClose);
            menuFile.add(menuItem);
            actionDelete = new ActionDelete();
            menuItem = new JMenuItem(actionDelete);
            menuFile.add(menuItem);
            frameMenuBar.add(menuFile);
        }
        return (frameMenuBar);
    }

    public void setPanelMode(CFJPanel.PanelMode value) {
        CFJPanel.PanelMode oldMode = getPanelMode();
        if (oldMode == value) {
            return;
        }
        super.setPanelMode(value);
        ((ICFAccSwingAccountConfigJPanelCommon) swingViewEditJPanel).setPanelMode(value);
        if (value == CFJPanel.PanelMode.View) {
            if (actionEdit != null) {
                actionEdit.setEnabled(true);
            }
            if (actionSave != null) {
                actionSave.setEnabled(false);
            }
            if (actionDelete != null) {
                actionDelete.setEnabled(true);
            }
            if (actionClose != null) {
                actionClose.setEnabled(true);
            }
        } else if (value == CFJPanel.PanelMode.Edit) {
            if (actionEdit != null) {
                actionEdit.setEnabled(false);
            }
            if (actionSave != null) {
                actionSave.setEnabled(true);
            }
            if (actionDelete != null) {
                actionDelete.setEnabled(false);
            }
            if (actionClose != null) {
                actionClose.setEnabled(true);
            }
        } else if (value == CFJPanel.PanelMode.Add) {
            if (actionEdit != null) {
                actionEdit.setEnabled(false);
            }
            if (actionSave != null) {
                actionSave.setEnabled(true);
            }
            if (actionDelete != null) {
                actionDelete.setEnabled(false);
            }
            if (actionClose != null) {
                actionClose.setEnabled(true);
            }
        } else {
            if (actionEdit != null) {
                actionEdit.setEnabled(false);
            }
            if (actionSave != null) {
                actionSave.setEnabled(false);
            }
            if (actionDelete != null) {
                actionDelete.setEnabled(false);
            }
            if (actionClose != null) {
                actionClose.setEnabled(true);
            }
        }
    }
}