net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSwing.CFAsteriskSwingSecGroupFinderJInternalFrame.java Source code

Java tutorial

Introduction

Here is the source code for net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSwing.CFAsteriskSwingSecGroupFinderJInternalFrame.java

Source

// Description: Java 8 Swing Finder JInternalFrame implementation for SecGroup.

/*
 *   Code Factory Asterisk 11 Configuration Model
 *
 *   Copyright (c) 2014-2015 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.
 *   
 */

package net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskSwing;

import java.math.*;
import java.sql.*;
import java.text.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import net.sourceforge.msscodefactory.cflib.v2_3.CFLib.*;
import net.sourceforge.msscodefactory.cflib.v2_3.CFLib.Swing.*;
import org.apache.commons.codec.binary.Base64;
import net.sourceforge.msscodefactory.cfsecurity.v2_4.CFSecurity.*;
import net.sourceforge.msscodefactory.cfinternet.v2_4.CFInternet.*;
import net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsterisk.*;
import net.sourceforge.msscodefactory.cfsecurity.v2_4.CFSecurityObj.*;
import net.sourceforge.msscodefactory.cfinternet.v2_4.CFInternetObj.*;
import net.sourceforge.msscodefactory.cfasterisk.v2_4.CFAsteriskObj.*;

/**
 *   CFAsteriskSwingSecGroupFinderJInternalFrame Swing Finder JInternalFrame implementation
 *   for SecGroup.
 */
public class CFAsteriskSwingSecGroupFinderJInternalFrame extends CFJInternalFrame
        implements ICFAsteriskSwingSecGroupJPanelCommon {
    protected ICFAsteriskSwingSchema swingSchema = null;
    protected JPanel swingFinderJPanel = null;
    protected JMenuBar finderMenuBar = null;
    protected JMenu menuFile = null;
    protected Action actionClose = null;
    protected JMenu menuAdd = null;
    protected ViewEditInternalFrameListener viewEditInternalFrameListener = null;
    protected Action actionAddSecGroup = null;
    protected ActionViewSelectedSecGroup actionViewSelected = null;
    protected ActionEditSelectedSecGroup actionEditSelected = null;
    protected ActionDeleteSelectedSecGroup actionDeleteSelected = null;

    protected class ViewEditInternalFrameListener implements InternalFrameListener {
        public ViewEditInternalFrameListener() {
        }

        public void internalFrameActivated(InternalFrameEvent e) {
        }

        public void internalFrameClosed(InternalFrameEvent e) {
            ((ICFJRefreshCallback) swingFinderJPanel).refreshMe();
        }

        public void internalFrameClosing(InternalFrameEvent e) {
        }

        public void internalFrameDeactivated(InternalFrameEvent e) {
        }

        public void internalFrameIconified(InternalFrameEvent e) {
        }

        public void internalFrameDeiconified(InternalFrameEvent e) {
        }

        public void internalFrameOpened(InternalFrameEvent e) {
        }
    }

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

        public void actionPerformed(ActionEvent e) {
            try {
                setClosed(true);
            } catch (Exception x) {
            }
        }
    }

    protected class ActionViewSelectedSecGroup extends AbstractAction {
        public ActionViewSelectedSecGroup() {
            super();
            putValue(Action.NAME, "View Selected...");
            setEnabled(true);
        }

        public void actionPerformed(ActionEvent e) {
            final String S_ProcName = "actionPerformed";
            ICFAsteriskSchemaObj schemaObj = swingSchema.getSchema();
            if (schemaObj == null) {
                throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                        "schemaObj");
            }
            ICFSecuritySecGroupObj selectedInstance = getSwingFocusAsSecGroup();
            if (selectedInstance != null) {
                String classCode = selectedInstance.getClassCode();
                if ("SGRP".equals(classCode)) {
                    JInternalFrame frame = swingSchema.getSecGroupFactory()
                            .newViewEditJInternalFrame(selectedInstance);
                    frame.addInternalFrameListener(getViewEditInternalFrameListener());
                    ((ICFAsteriskSwingSecGroupJPanelCommon) frame).setPanelMode(CFJPanel.PanelMode.View);
                    getDesktopPane().add(frame);
                    frame.setVisible(true);
                    frame.show();
                } else {
                    throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName,
                            "selectedInstance", selectedInstance, "ICFAsteriskSecGroupObj");
                }
            }
        }
    }

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

        public void actionPerformed(ActionEvent e) {
            final String S_ProcName = "actionPerformed";
            ICFAsteriskSchemaObj schemaObj = swingSchema.getSchema();
            if (schemaObj == null) {
                throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                        "schemaObj");
            }
            ICFSecuritySecGroupObj selectedInstance = getSwingFocusAsSecGroup();
            if (selectedInstance != null) {
                String classCode = selectedInstance.getClassCode();
                if ("SGRP".equals(classCode)) {
                    JInternalFrame frame = swingSchema.getSecGroupFactory()
                            .newViewEditJInternalFrame(selectedInstance);
                    frame.addInternalFrameListener(getViewEditInternalFrameListener());
                    ((ICFAsteriskSwingSecGroupJPanelCommon) frame).setPanelMode(CFJPanel.PanelMode.Edit);
                    getDesktopPane().add(frame);
                    frame.setVisible(true);
                    frame.show();
                } else {
                    throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName,
                            "selectedInstance", selectedInstance, "ICFAsteriskSecGroupObj");
                }
            }
        }
    }

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

        public void actionPerformed(ActionEvent e) {
            final String S_ProcName = "actionPerformed";
            ICFAsteriskSchemaObj schemaObj = swingSchema.getSchema();
            if (schemaObj == null) {
                throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                        "schemaObj");
            }
            ICFSecuritySecGroupObj selectedInstance = getSwingFocusAsSecGroup();
            if (selectedInstance != null) {
                String classCode = selectedInstance.getClassCode();
                if ("SGRP".equals(classCode)) {
                    JInternalFrame frame = swingSchema.getSecGroupFactory()
                            .newAskDeleteJInternalFrame(selectedInstance);
                    ((ICFAsteriskSwingSecGroupJPanelCommon) frame).setPanelMode(CFJPanel.PanelMode.View);
                    frame.addInternalFrameListener(getViewEditInternalFrameListener());
                    getDesktopPane().add(frame);
                    frame.setVisible(true);
                    frame.show();
                } else {
                    throw CFLib.getDefaultExceptionFactory().newUnsupportedClassException(getClass(), S_ProcName,
                            "selectedInstance", selectedInstance, "ICFAsteriskSecGroupObj");
                }
            }
        }
    }

    protected class ActionAddSecGroup extends AbstractAction {
        public ActionAddSecGroup() {
            super();
            putValue(Action.NAME, "Add Security Group...");
            setEnabled(true);
        }

        public void actionPerformed(ActionEvent e) {
            final String S_ProcName = "actionPerformed";
            ICFAsteriskSchemaObj schemaObj = swingSchema.getSchema();
            if (schemaObj == null) {
                throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                        "schemaObj");
            }
            ICFAsteriskSecGroupObj obj = (ICFAsteriskSecGroupObj) schemaObj.getSecGroupTableObj().newInstance();
            ICFAsteriskSecGroupEditObj edit = (ICFAsteriskSecGroupEditObj) (obj.beginEdit());
            if (edit == null) {
                throw CFLib.getDefaultExceptionFactory().newNullArgumentException(getClass(), S_ProcName, 0,
                        "edit");
            }
            ICFSecurityClusterObj secCluster = schemaObj.getSecCluster();
            edit.setRequiredContainerCluster(secCluster);
            JInternalFrame frame = swingSchema.getSecGroupFactory().newViewEditJInternalFrame(obj);
            frame.addInternalFrameListener(getViewEditInternalFrameListener());
            ICFAsteriskSwingSecGroupJPanelCommon jpanelCommon = (ICFAsteriskSwingSecGroupJPanelCommon) frame;
            jpanelCommon.setPanelMode(CFJPanel.PanelMode.Add);
            getDesktopPane().add(frame);
            frame.setVisible(true);
            frame.show();
        }
    }

    public CFAsteriskSwingSecGroupFinderJInternalFrame(ICFAsteriskSwingSchema argSchema) {
        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);
        swingSchema = argSchema;
        swingFinderJPanel = argSchema.getSecGroupFactory().newFinderJPanel();
        setContentPane(swingFinderJPanel);
        Dimension dim = new Dimension(1024, 480);
        setSize(dim);
        dim = new Dimension(320, 240);
        setMinimumSize(dim);
        setTitle("Find Security Group");
        setJMenuBar(getFinderMenuBar());
        setIconifiable(true);
        setMaximizable(true);
        setResizable(true);
        setClosable(false);
        adjustFinderMenuBar();
    }

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

    public JMenuBar getFinderMenuBar() {
        if (finderMenuBar == null) {
            JMenuItem menuItem;
            finderMenuBar = new JMenuBar();
            menuFile = new JMenu("File");
            actionAddSecGroup = new ActionAddSecGroup();
            menuItem = new JMenuItem(actionAddSecGroup);
            menuFile.add(menuItem);
            actionViewSelected = new ActionViewSelectedSecGroup();
            menuItem = new JMenuItem(actionViewSelected);
            menuFile.add(menuItem);
            actionEditSelected = new ActionEditSelectedSecGroup();
            menuItem = new JMenuItem(actionEditSelected);
            menuFile.add(menuItem);
            actionDeleteSelected = new ActionDeleteSelectedSecGroup();
            menuItem = new JMenuItem(actionDeleteSelected);
            menuFile.add(menuItem);
            actionClose = new ActionClose();
            menuItem = new JMenuItem(actionClose);
            menuFile.add(menuItem);
            finderMenuBar.add(menuFile);
        }
        return (finderMenuBar);
    }

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

    public ICFSecuritySecGroupObj getSwingFocusAsSecGroup() {
        return ((ICFSecuritySecGroupObj) getSwingFocus());
    }

    public void setSwingFocusAsSecGroup(ICFSecuritySecGroupObj value) {
        setSwingFocus(value);
    }

    public void adjustFinderMenuBar() {
        JMenuItem menuItem;
        Action act;
        String itemLabel;
        ICFSecuritySecGroupObj selectedObj = getSwingFocusAsSecGroup();
        boolean enableState;
        if (selectedObj == null) {
            enableState = false;
        } else {
            enableState = true;
        }

        if (actionViewSelected != null) {
            actionViewSelected.setEnabled(enableState);
        }
        if (actionEditSelected != null) {
            actionEditSelected.setEnabled(enableState);
        }
        if (actionDeleteSelected != null) {
            actionDeleteSelected.setEnabled(enableState);
        }
        if (actionAddSecGroup != null) {
            actionAddSecGroup.setEnabled(true);
        }

        if (menuFile != null) {
            int itemCount = menuFile.getItemCount();
            for (int itemIdx = 0; itemIdx < itemCount; itemIdx++) {
                menuItem = menuFile.getItem(itemIdx);
                act = menuItem.getAction();
                if (act != null) {
                    if (act == actionViewSelected) {
                        menuItem.setEnabled(enableState);
                    } else if (act == actionEditSelected) {
                        menuItem.setEnabled(enableState);
                    } else if (act == actionDeleteSelected) {
                        menuItem.setEnabled(enableState);
                    } else if (act == actionAddSecGroup) {
                        menuItem.setEnabled(true);
                    }
                }
            }
        }
    }

    protected ViewEditInternalFrameListener getViewEditInternalFrameListener() {
        if (viewEditInternalFrameListener == null) {
            viewEditInternalFrameListener = new ViewEditInternalFrameListener();
        }
        return (viewEditInternalFrameListener);
    }
}