net.sourceforge.msscodefactory.cfcrm.v2_0.CFCrmSwing.CFCrmSwingServiceAskDeleteJPanel.java Source code

Java tutorial

Introduction

Here is the source code for net.sourceforge.msscodefactory.cfcrm.v2_0.CFCrmSwing.CFCrmSwingServiceAskDeleteJPanel.java

Source

// Description: Java 7 Swing Ask Delete JPanel implementation for Service.

/*
 *   CF Customer Relations Management model
 *
 *   Copyright (c) 2010-2014 Mark Sobkow
 *   
 *      Licensed under the Apache License, Version 2.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.apache.org/licenses/LICENSE-2.0
 *   
 *      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.
 *   
 * ***********************************************************************
 *
 *   Code manufactured by MSS Code Factory
 */

package net.sourceforge.msscodefactory.cfcrm.v2_0.CFCrmSwing;

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.cfcrm.v2_0.CFCrm.*;
import net.sourceforge.msscodefactory.cfcrm.v2_0.CFCrmObj.*;

/**
 *   CFCrmSwingServiceAskDeleteJPanel Swing Ask Delete JPanel implementation
 *   for Service.
 */
public class CFCrmSwingServiceAskDeleteJPanel extends CFJPanel implements ICFCrmSwingServiceJPanelCommon {
    protected ICFCrmSwingSchema swingSchema = null;
    protected JTextArea textAreaMessage = null;

    protected class ActionOk extends AbstractAction {
        public ActionOk() {
            super();
            putValue(Action.NAME, "Ok");
            setEnabled(true);
        }

        public void actionPerformed(ActionEvent e) {
            final String S_ProcName = "actionPerformed";
            Container cont = getParent();
            while ((cont != null) && (!(cont instanceof JInternalFrame))) {
                cont = cont.getParent();
            }
            if (cont != null) {
                JInternalFrame frame = (JInternalFrame) cont;
                if (frame instanceof ICFCrmSwingServiceJPanelCommon) {
                    ICFCrmSwingServiceJPanelCommon jpanelCommon = (ICFCrmSwingServiceJPanelCommon) frame;
                    jpanelCommon.setPanelMode(CFJPanel.PanelMode.Delete);
                } else {
                    throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName,
                            "frame", frame, "ICFCrmSwingServiceJPanelCommon");
                }
                try {
                    frame.setClosed(true);
                } catch (Exception x) {
                }
            }
        }
    }

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

        public void actionPerformed(ActionEvent e) {
            final String S_ProcName = "actionPerformed";
            Container cont = getParent();
            while ((cont != null) && (!(cont instanceof JInternalFrame))) {
                cont = cont.getParent();
            }
            if (cont != null) {
                JInternalFrame frame = (JInternalFrame) cont;
                if (frame instanceof ICFCrmSwingServiceJPanelCommon) {
                    ICFCrmSwingServiceJPanelCommon jpanelCommon = (ICFCrmSwingServiceJPanelCommon) frame;
                    jpanelCommon.setPanelMode(CFJPanel.PanelMode.Unknown);
                    ICFCrmServiceEditObj editObj = (ICFCrmServiceEditObj) jpanelCommon.getSwingFocusAsService()
                            .getEdit();
                    if (editObj != null) {
                        editObj.endEdit();
                    }
                } else {
                    throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName,
                            "frame", frame, "ICFCrmSwingServiceJPanelCommon");
                }
                try {
                    frame.setClosed(true);
                } catch (Exception x) {
                }
            }
        }
    }

    protected Action actionOk = null;
    protected Action actionCancel = null;
    protected JButton buttonOk = null;
    protected JButton buttonCancel = null;
    protected JScrollPane scrollPane = null;
    protected JPanel attrJPanel = null;

    public CFCrmSwingServiceAskDeleteJPanel(ICFCrmSwingSchema argSchema, ICFCrmServiceObj argFocus) {
        super();
        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;
        swingFocus = argFocus;
        // Construct the various objects
        textAreaMessage = new JTextArea("Are you sure you want to delete this Service?");
        actionOk = new ActionOk();
        actionCancel = new ActionCancel();
        buttonOk = new JButton(actionOk);
        buttonCancel = new JButton(actionCancel);
        attrJPanel = argSchema.getServiceFactory().newAttrJPanel(argFocus);
        scrollPane = new CFHSlaveJScrollPane(attrJPanel);
        // Lay out the widgets
        setSize(1024, 480);
        Dimension min = new Dimension(480, 300);
        setMinimumSize(min);
        add(textAreaMessage);
        textAreaMessage.setBounds(0, 0, 1024, 50);
        int xparts = (768 - (2 * 125)) / 3;
        add(buttonOk);
        buttonOk.setBounds(xparts, 55, 125, 40);
        add(buttonCancel);
        buttonCancel.setBounds(xparts + 125 + xparts, 55, 125, 40);
        add(scrollPane);
        scrollPane.setBounds(0, 100, 1024, 480 - 100);
    }

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

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

    public ICFCrmServiceObj getSwingFocusAsService() {
        return ((ICFCrmServiceObj) getSwingFocus());
    }

    public void setSwingFocusAsService(ICFCrmServiceObj value) {
        swingFocus = value;
        if (attrJPanel != null) {
            ((ICFCrmSwingServiceJPanelCommon) attrJPanel).setSwingFocus(value);
        }
    }

    public void doLayout() {
        Dimension sz = getSize();
        textAreaMessage.setBounds(0, 0, sz.width, 50);
        int xparts = (sz.width - (2 * 125)) / 3;
        buttonOk.setBounds(xparts, 55, 125, 40);
        buttonCancel.setBounds(xparts + 125 + xparts, 55, 125, 40);
        scrollPane.setBounds(0, 100, sz.width, sz.height - 100);
        scrollPane.doLayout();
    }

    public void setPanelMode(CFJPanel.PanelMode value) {
        final String S_ProcName = "setPanelMode";
        CFJPanel.PanelMode oldMode = getPanelMode();
        if (oldMode == value) {
            return;
        }
        if ((value != CFJPanel.PanelMode.Unknown) && (value != CFJPanel.PanelMode.View)
                && (value != CFJPanel.PanelMode.Delete)) {
            throw CFLib.getDefaultExceptionFactory().newUsageException(getClass(), S_ProcName,
                    "AskDeleteJPanels only support PanelMode Unknown, View or Delete");
        }
        super.setPanelMode(value);
        if (attrJPanel != null) {
            ((ICFCrmSwingServiceJPanelCommon) attrJPanel).setPanelMode(value);
        }
    }
}