Example usage for javax.swing JInternalFrame setClosed

List of usage examples for javax.swing JInternalFrame setClosed

Introduction

In this page you can find the example usage for javax.swing JInternalFrame setClosed.

Prototype

@BeanProperty(description = "Indicates whether this internal frame has been closed.")
public void setClosed(boolean b) throws PropertyVetoException 

Source Link

Document

Closes this internal frame if the argument is true.

Usage

From source file:mondrian.gui.Workbench.java

private void closeAllSchemaFrames(boolean exitAfterClose) {
    try {//from  w w w .  j  a v  a 2s  .  c  o m
        for (JInternalFrame sf : getAllFrames()) {
            if (sf == null) {
                continue;
            }
            if (sf.getContentPane().getComponent(0) instanceof SchemaExplorer) {
                SchemaExplorer se = (SchemaExplorer) sf.getContentPane().getComponent(0);
                sf.setSelected(true);
                int response = confirmFrameClose(sf, se);
                switch (response) {
                case 2:
                    // cancel
                    return;
                case 3:
                    // not dirty
                    sf.setClosed(true);
                    break;
                }
            } else {
                sf.setClosed(true);
            }
        }
        // exit Schema Workbench if no files are open
        if (((schemaWindowMap.keySet().size()) == 0) && exitAfterClose) {
            System.exit(0);
        }
    } catch (Exception ex) {
        LOGGER.error("closeAllSchemaFrames", ex);
    }
}

From source file:mondrian.gui.Workbench.java

private void openSchemaFrame(File file, boolean newFile) {
    try {// ww w  .  j a  va2  s.c  om
        setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));

        if (!newFile) {
            // check if file not already open
            if (checkFileOpen(file)) {
                return;
            }
            // check if schema file exists
            if (!file.exists()) {
                JOptionPane.showMessageDialog(this,
                        getResourceConverter().getFormattedString("workbench.open.schema.not.found",
                                "{0} File not found.", file.getAbsolutePath()),
                        getResourceConverter().getString("workbench.open.schema.not.found.title", "Alert"),
                        JOptionPane.WARNING_MESSAGE);
                return;
            }
            // check if file is writable
            if (!file.canWrite()) {
                JOptionPane.showMessageDialog(this,
                        getResourceConverter().getFormattedString("workbench.open.schema.not.writeable",
                                "{0} is not writeable.", file.getAbsolutePath()),
                        getResourceConverter().getString("workbench.open.schema.not.writeable.title", "Alert"),
                        JOptionPane.WARNING_MESSAGE);
                return;
            }
            checkSchemaFile(file);
        }

        final JInternalFrame schemaFrame = new JInternalFrame();
        schemaFrame.setTitle(getResourceConverter().getFormattedString("workbench.open.schema.title",
                "Schema - {0}", file.getName()));

        getNewJdbcMetadata();

        schemaFrame.getContentPane().add(new SchemaExplorer(this, file, jdbcMetaData, newFile, schemaFrame));

        String errorOpening = ((SchemaExplorer) schemaFrame.getContentPane().getComponent(0)).getErrMsg();
        if (errorOpening != null) {
            JOptionPane.showMessageDialog(this,
                    getResourceConverter().getFormattedString("workbench.open.schema.error",
                            "Error opening schema - {0}.", errorOpening),
                    getResourceConverter().getString("workbench.open.schema.error.title", "Error"),
                    JOptionPane.ERROR_MESSAGE);
            schemaFrame.setClosed(true);
            return;
        }

        schemaFrame.setBounds(0, 0, 1000, 650);
        schemaFrame.setClosable(true);
        schemaFrame.setIconifiable(true);
        schemaFrame.setMaximizable(true);
        schemaFrame.setResizable(true);
        schemaFrame.setVisible(true);

        desktopPane.add(schemaFrame, javax.swing.JLayeredPane.DEFAULT_LAYER);
        schemaFrame.show();
        schemaFrame.setMaximum(true);

        displayWarningOnFailedConnection();

        final javax.swing.JMenuItem schemaMenuItem = new javax.swing.JMenuItem();
        schemaMenuItem.setText(windowMenuMapIndex++ + " " + file.getName());
        schemaMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                try {
                    if (schemaFrame.isIcon()) {
                        schemaFrame.setIcon(false);
                    } else {
                        schemaFrame.setSelected(true);
                    }
                } catch (Exception ex) {
                    LOGGER.error("schemaMenuItem", ex);
                }
            }
        });

        windowMenu.add(schemaMenuItem, 0);
        windowMenu.setEnabled(true);

        windowMenu.add(jSeparator3, -1);
        windowMenu.add(cascadeMenuItem, -1);
        windowMenu.add(tileMenuItem, -1);
        windowMenu.add(minimizeMenuItem, -1);
        windowMenu.add(maximizeMenuItem, -1);
        windowMenu.add(closeAllMenuItem, -1);

        // add the file details in menu map
        schemaWindowMap.put(schemaFrame, schemaMenuItem);
        updateMDXCatalogList();

        schemaFrame.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);

        schemaFrame.addInternalFrameListener(new InternalFrameAdapter() {
            public void internalFrameClosing(InternalFrameEvent e) {
                if (schemaFrame.getContentPane().getComponent(0) instanceof SchemaExplorer) {
                    SchemaExplorer se = (SchemaExplorer) schemaFrame.getContentPane().getComponent(0);
                    int response = confirmFrameClose(schemaFrame, se);
                    if (response == 3) { // not dirty
                        if (se.isNewFile()) {
                            se.getSchemaFile().delete();
                        }
                        // default case for no save and not dirty
                        schemaWindowMap.remove(schemaFrame);
                        updateMDXCatalogList();
                        schemaFrame.dispose();
                        windowMenu.remove(schemaMenuItem);
                    }
                }
            }
        });

        schemaFrame.setFocusable(true);
        schemaFrame.addFocusListener(new FocusAdapter() {
            public void focusGained(FocusEvent e) {
                if (schemaFrame.getContentPane().getComponent(0) instanceof SchemaExplorer) {
                    SchemaExplorer se = (SchemaExplorer) schemaFrame.getContentPane().getComponent(0);
                    // update view menu based on schemaframe who gained
                    // focus
                    viewXmlMenuItem.setSelected(se.isEditModeXML());
                }
            }

            public void focusLost(FocusEvent e) {
                if (schemaFrame.getContentPane().getComponent(0) instanceof SchemaExplorer) {
                    SchemaExplorer se = (SchemaExplorer) schemaFrame.getContentPane().getComponent(0);
                    // update view menu based on
                    viewXmlMenuItem.setSelected(se.isEditModeXML());
                }
            }
        });
        viewXmlMenuItem.setSelected(false);
    } catch (Exception ex) {
        LOGGER.error("openSchemaFrame", ex);
    } finally {
        setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
    }
}

From source file:mondrian.gui.Workbench.java

private int confirmFrameClose(JInternalFrame schemaFrame, SchemaExplorer se) {
    if (se.isDirty()) {
        JMenuItem schemaMenuItem = schemaWindowMap.get(desktopPane.getSelectedFrame());
        // yes=0; no=1; cancel=2
        int answer = JOptionPane.showConfirmDialog(null,
                getResourceConverter().getFormattedString("workbench.saveSchemaOnClose.alert",
                        "Save changes to {0}?", se.getSchemaFile().toString()),
                getResourceConverter().getString("workbench.saveSchemaOnClose.title", "Schema"),
                JOptionPane.YES_NO_CANCEL_OPTION);
        switch (answer) {
        case 0:// w  ww. j  a v a  2s  .com
            saveMenuItemActionPerformed(null);
            schemaWindowMap.remove(schemaFrame);
            updateMDXCatalogList();
            schemaFrame.dispose();
            windowMenu.remove(schemaMenuItem);
            break;
        case 1:
            schemaFrame.dispose();
            schemaWindowMap.remove(schemaFrame);
            windowMenu.remove(schemaMenuItem);
            break;
        case 2:
            try {
                schemaFrame.setClosed(false);
                schemaFrame.show();
            } catch (Exception ex) {
                LOGGER.error(ex);
            }
        }
        return answer;
    }
    return 3;
}