Example usage for javax.swing JMenuItem setText

List of usage examples for javax.swing JMenuItem setText

Introduction

In this page you can find the example usage for javax.swing JMenuItem setText.

Prototype

@BeanProperty(preferred = true, visualUpdate = true, description = "The button's text.")
public void setText(String text) 

Source Link

Document

Sets the button's text.

Usage

From source file:com.dfki.av.sudplan.ui.MainFrame.java

private void miSaveViewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_miSaveViewActionPerformed

    String defaultName = "View " + viewID;
    String name = JOptionPane.showInputDialog(this, "Enter a name for the view", defaultName);
    if (name == null) {
        log.debug("Cancled JOptionPane.");
        return;/*from   w  w w.ja  va  2 s. c  o  m*/
    }
    if (name.isEmpty()) {
        String msg = "Server URL is empty";
        log.error(msg);
        name = defaultName;
    }

    WorldWindowGLCanvas worldWindow = wwPanel.getWwd();
    View view = worldWindow.getView();
    String xml = view.getRestorableState();
    log.info(xml);

    final Position eyePosition = view.getEyePosition();
    final Position centerPosition = view.getGlobe().computePositionFromPoint(view.getCenterPoint());
    log.info("Saving view: eye({}), center({})", eyePosition.toString(), centerPosition.toString());

    JMenuItem menuItem = new JMenuItem(new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            WorldWindowGLCanvas canvas = wwPanel.getWwd();
            View view = canvas.getView();
            view.setOrientation(eyePosition, centerPosition);
            canvas.redraw();
        }
    });
    menuItem.setText(name);
    mCustomViewPoints.add(menuItem);
    viewID++;
}

From source file:at.becast.youploader.gui.FrmMain.java

public void initMenuBar() {
    JMenuBar mnuBar = new JMenuBar();
    JMenu mnuFile = new JMenu();
    JMenuItem mnuQuit = new JMenuItem();
    mnuAcc = new JMenu();

    mnuFile.setText(LANG.getString("frmMain.menu.File"));

    mnuQuit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, InputEvent.ALT_MASK));
    mnuQuit.setText(LANG.getString("frmMain.menu.Quit"));
    mnuQuit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            mnuQuitActionPerformed();//from  w  w w .  j  a va2  s  .  c om
        }
    });
    mnuFile.add(mnuQuit);

    mnuBar.add(mnuFile);

    mnuAcc.setText(LANG.getString("frmMain.menu.Account"));
    mnuBar.add(mnuAcc);

    JSeparator separator = new JSeparator();
    JMenuItem mntmAddAccount = new JMenuItem(LANG.getString("frmMain.menu.AddAccount"));
    mntmAddAccount.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            mntmAddAccountActionPerformed();
        }
    });
    mnuAcc.add(mntmAddAccount);
    mnuAcc.add(separator);

    JMenu mnLanguage = new JMenu("Language");
    mnLanguage.setVisible(false);
    mnLanguage.setEnabled(false);
    mnuBar.add(mnLanguage);

    JMenu menu = new JMenu("?");
    mnuBar.add(menu);

    JMenuItem mntmDonate = new JMenuItem(LANG.getString("frmMain.menu.Donate"));
    menu.add(mntmDonate);
    mntmDonate.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            donateButton();
        }
    });

    JMenuItem mntmAbout = new JMenuItem(LANG.getString("frmMain.menu.About"));
    mntmAbout.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            FrmAbout about = new FrmAbout();
            about.setVisible(true);
        }
    });
    menu.add(mntmAbout);

    JMenuItem mntmShowLogfile = new JMenuItem(LANG.getString("frmMain.menu.ShowLogfile"));
    mntmShowLogfile.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            DesktopUtil.openDir(new File(System.getProperty("user.home") + "/YouPloader"));
        }
    });
    menu.add(mntmShowLogfile);

    JMenuItem mntmUploadLogfile = new JMenuItem(LANG.getString("frmMain.menu.UploadLatestLogfile"));
    mntmUploadLogfile.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            DesktopUtil.openDir(new File(System.getProperty("user.home") + "/YouPloader"));
        }
    });
    menu.add(mntmUploadLogfile);

    chckbxmntmCheckForUpdates = new JCheckBoxMenuItem(LANG.getString("frmMain.menu.CheckforUpdates"));
    menu.add(chckbxmntmCheckForUpdates);
    if (Main.s.setting.get("notify_updates").equals("1")) {
        chckbxmntmCheckForUpdates.setSelected(true);
    }
    chckbxmntmCheckForUpdates.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            toggleUpdateNotifier();
        }
    });
    setJMenuBar(mnuBar);
}

From source file:biz.wolschon.finance.jgnucash.JGnucash.java

/**
 * This method initializes import-menu/*from  w ww.  j av a  2 s.  co m*/
 * with plugins.
 *
 * @return javax.swing.JMenu
 */
@SuppressWarnings("unchecked")
protected JMenu getToolMenu() {
    if (toolMenu == null) {
        toolMenu = new JMenu();
        toolMenu.setText("Tools");
        toolMenu.setMnemonic('t');
        //importMenu.setEnabled(false);// first we need to load a file

        PluginManager manager = getPluginManager();
        // if we are configured for the plugin-api
        if (manager != null) {
            ExtensionPoint toolExtPoint = manager.getRegistry().getExtensionPoint(getPluginDescriptor().getId(),
                    "Tool");
            for (Iterator<Extension> it = toolExtPoint.getConnectedExtensions().iterator(); it.hasNext();) {
                Extension ext = it.next();
                String pluginName = "unknown";

                try {
                    pluginName = ext.getParameter("name").valueAsString();
                    JMenuItem newMenuItem = new JMenuItem();
                    newMenuItem.putClientProperty("extension", ext);
                    Parameter descrParam = ext.getParameter("description");
                    Parameter iconParam = ext.getParameter("icon");
                    URL iconUrl = null;
                    if (iconParam != null) {
                        try {
                            iconUrl = getPluginManager()
                                    .getPluginClassLoader(ext.getDeclaringPluginDescriptor())
                                    .getResource(iconParam.valueAsString());
                            if (iconUrl != null) {
                                newMenuItem.setIcon(new ImageIcon(iconUrl));
                            }
                        } catch (Exception e) {
                            LOGGER.error("cannot load icon for Tool-Plugin '" + pluginName + "'", e);
                        }
                    }
                    newMenuItem.setText(pluginName);
                    if (descrParam != null) {
                        newMenuItem.setToolTipText(descrParam.valueAsString());
                    }
                    newMenuItem.addActionListener(new ToolPluginMenuAction(this, ext, pluginName));
                    toolMenu.add(newMenuItem);
                } catch (Exception e) {
                    LOGGER.error("cannot load Tool-Plugin '" + pluginName + "'", e);
                    JOptionPane.showMessageDialog(this, "Error", "Cannot load Tool-Plugin '" + pluginName + "'",
                            JOptionPane.ERROR_MESSAGE);
                }
            }
        }
    }
    return toolMenu;
}

From source file:biz.wolschon.finance.jgnucash.JGnucash.java

/**
 * This method initializes import-menu with
 * plugins.//  w ww.  j ava2s.  com
 *
 * @return javax.swing.JMenu
 */
@SuppressWarnings("unchecked")
protected JMenu getImportMenu() {
    if (importMenu == null) {
        importMenu = new JMenu();
        importMenu.setText("Import");
        importMenu.setMnemonic('i');
        //importMenu.setEnabled(false);// first we need to load a file

        PluginManager manager = getPluginManager();
        // if we are configured for the plugin-api
        if (manager != null) {
            ExtensionPoint toolExtPoint = manager.getRegistry().getExtensionPoint(getPluginDescriptor().getId(),
                    "Importer");
            for (Iterator<Extension> it = toolExtPoint.getConnectedExtensions().iterator(); it.hasNext();) {
                Extension ext = it.next();
                String pluginName = "unknown";

                try {
                    pluginName = ext.getParameter("name").valueAsString();
                    JMenuItem newMenuItem = new JMenuItem();
                    newMenuItem.putClientProperty("extension", ext);
                    Parameter descrParam = ext.getParameter("description");
                    Parameter iconParam = ext.getParameter("icon");
                    URL iconUrl = null;
                    if (iconParam != null) {
                        try {
                            iconUrl = getPluginManager()
                                    .getPluginClassLoader(ext.getDeclaringPluginDescriptor())
                                    .getResource(iconParam.valueAsString());
                            if (iconUrl != null) {
                                newMenuItem.setIcon(new ImageIcon(iconUrl));
                            }
                        } catch (Exception e) {
                            LOGGER.error("cannot load icon for Importer-Plugin '" + pluginName + "'", e);
                        }
                    }
                    newMenuItem.setText(pluginName);
                    if (descrParam != null) {
                        newMenuItem.setToolTipText(descrParam.valueAsString());
                    }
                    newMenuItem.addActionListener(new ImportPluginMenuAction(this, ext, pluginName));
                    importMenu.add(newMenuItem);
                } catch (Exception e) {
                    LOGGER.error("cannot load Importer-Plugin '" + pluginName + "'", e);
                    JOptionPane.showMessageDialog(this, "Error",
                            "Cannot load Importer-Plugin '" + pluginName + "'", JOptionPane.ERROR_MESSAGE);
                }
            }
        }
    }
    return importMenu;
}

From source file:org.gumtree.vis.plot1d.Plot1DPanel.java

@Override
protected void displayPopupMenu(int x, int y) {
    LegendTitle legend = getChart().getLegend();
    if (legend != null) {
        boolean isVisable = legend.isVisible();
        RectangleEdge location = legend.getPosition();
        if (isVisable) {
            if (location.equals(RectangleEdge.BOTTOM)) {
                legendBottom.setSelected(true);
                legendNone.setSelected(false);
                legendInternal.setSelected(false);
                legendRight.setSelected(false);
            } else if (isVisable && location.equals(RectangleEdge.RIGHT)) {
                legendRight.setSelected(true);
                legendNone.setSelected(false);
                legendInternal.setSelected(false);
                legendBottom.setSelected(false);
            }//from w  w w  .j a v  a 2 s . c  o m
        } else {
            if (isInternalLegendEnabled) {
                legendNone.setSelected(false);
                legendInternal.setSelected(true);
                legendRight.setSelected(false);
                legendBottom.setSelected(false);
            } else {
                legendNone.setSelected(true);
                legendInternal.setSelected(false);
                legendRight.setSelected(false);
                legendBottom.setSelected(false);
            }
        }
    }
    XYDataset dataset = getChart().getXYPlot().getDataset();
    curveManagementMenu.removeAll();
    if (dataset.getSeriesCount() > 0) {
        curveManagementMenu.setEnabled(true);
        JMenuItem focusNoneCurveItem = new JRadioButtonMenuItem();
        focusNoneCurveItem.setText("None");
        focusNoneCurveItem.setActionCommand(UNFOCUS_CURVE_COMMAND);
        focusNoneCurveItem.addActionListener(this);
        curveManagementMenu.add(focusNoneCurveItem);
        boolean isCurveFocused = false;
        for (int i = 0; i < dataset.getSeriesCount(); i++) {
            String seriesKey = (String) dataset.getSeriesKey(i);
            JMenuItem focusOnCurveItem = new JRadioButtonMenuItem();
            focusOnCurveItem.setText(seriesKey);
            focusOnCurveItem.setActionCommand(FOCUS_ON_COMMAND + "-" + seriesKey);
            focusOnCurveItem.addActionListener(this);
            curveManagementMenu.add(focusOnCurveItem);
            if (i == selectedSeriesIndex) {
                focusOnCurveItem.setSelected(true);
                isCurveFocused = true;
            }
        }
        if (!isCurveFocused) {
            focusNoneCurveItem.setSelected(true);
        }
    } else {
        curveManagementMenu.setEnabled(false);
    }
    //        addMaskMenu(x, y);
    super.displayPopupMenu(x, y);
}

From source file:biz.wolschon.finance.jgnucash.JGnucash.java

/**
 * This method initializes FileMenu/*from ww  w. ja va  2  s . co  m*/
 * including all menu-items added by plugins.
 *
 * @return javax.swing.JMenu
 */
@SuppressWarnings("unchecked")
@Override
protected JMenu getFileMenu() {
    if (fileMenu == null) {
        fileMenu = super.getFileMenu();
        fileMenu.setText("File");
        fileMenu.setMnemonic('f');
        int i = 1;
        fileMenu.add(getFileSaveMenuItem(), i++);
        fileMenu.add(getFileSaveAsMenuItem(), i++);

        // allow plugins to supply file-open and file-save -actions
        PluginManager manager = getPluginManager();
        // if we are configured for the plugin-api
        if (manager != null) {
            ExtensionPoint toolExtPoint = manager.getRegistry().getExtensionPoint(getPluginDescriptor().getId(),
                    "DataSource");
            for (Iterator<Extension> it = toolExtPoint.getConnectedExtensions().iterator(); it.hasNext();) {
                Extension ext = it.next();
                String pluginName = "unknown";

                try {
                    pluginName = ext.getParameter("name").valueAsString();

                    LOGGER.debug("adding menu-item for DataSource-plugin " + pluginName
                            + " - support for writeTo=" + ext.getParameter("supportsWritingTo"));
                    JMenuItem newMenuItem = new JMenuItem();
                    newMenuItem.putClientProperty("extension", ext);
                    Parameter descrParam = ext.getParameter("description");
                    Parameter iconParam = ext.getParameter("icon");
                    URL iconUrl = null;
                    if (iconParam != null) {
                        try {
                            iconUrl = getPluginManager()
                                    .getPluginClassLoader(ext.getDeclaringPluginDescriptor())
                                    .getResource(iconParam.valueAsString());
                            if (iconUrl != null) {
                                newMenuItem.setIcon(new ImageIcon(iconUrl));
                            }
                        } catch (Exception e) {
                            LOGGER.error("cannot load icon for Loader-Plugin '" + pluginName + "'", e);
                        }
                    }
                    newMenuItem.setText("open via " + pluginName + "...");
                    if (descrParam != null) {
                        newMenuItem.setToolTipText(descrParam.valueAsString());
                    }
                    newMenuItem.addActionListener(new OpenFilePluginMenuAction(this, ext, pluginName));
                    fileMenu.add(newMenuItem, 1); // Open
                    if (ext.getParameter("supportsWritingTo").valueAsString().equalsIgnoreCase("true")) {
                        LOGGER.debug("Plugin " + pluginName + " also supportes 'write to', adding menu-item");
                        JMenuItem newSaveAsMenuItem = new JMenuItem();
                        newSaveAsMenuItem.putClientProperty("extension", ext);
                        newSaveAsMenuItem.setText("Save to via " + pluginName + "...");
                        if (iconUrl != null) {
                            newMenuItem.setIcon(new ImageIcon(iconUrl));
                        }
                        newSaveAsMenuItem
                                .addActionListener(new SaveAsFilePluginMenuAction(this, ext, pluginName));
                        fileMenu.add(newSaveAsMenuItem, 2); // Open

                    }
                } catch (Exception e) {
                    LOGGER.error("cannot load Loader-Plugin '" + pluginName + "'", e);
                    JOptionPane.showMessageDialog(this, "Error",
                            "Cannot load Loader-Plugin '" + pluginName + "'", JOptionPane.ERROR_MESSAGE);
                }
            }
        }
    }
    return fileMenu;
}

From source file:mondrian.gui.Workbench.java

private void newQueryMenuItemActionPerformed(ActionEvent evt) {
    JMenuItem schemaMenuItem = schemaWindowMap.get(desktopPane.getSelectedFrame());

    final JInternalFrame jf = new JInternalFrame();
    jf.setTitle(getResourceConverter().getString("workbench.new.MDXQuery.title", "MDX Query"));
    QueryPanel qp = new QueryPanel(this);

    jf.getContentPane().add(qp);// ww  w  .  jav  a  2s . c  o m
    jf.setBounds(0, 0, 500, 480);
    jf.setClosable(true);
    jf.setIconifiable(true);
    jf.setMaximizable(true);
    jf.setResizable(true);
    jf.setVisible(true);

    desktopPane.add(jf);
    jf.show();
    try {
        jf.setSelected(true);
    } catch (Exception ex) {
        // do nothing
        LOGGER.error("newQueryMenuItemActionPerformed.setSelected", ex);
    }

    // add the mdx frame to this set of mdx frames for cascading method
    mdxWindows.add(jf);

    // create mdx menu item
    final javax.swing.JMenuItem queryMenuItem = new javax.swing.JMenuItem();
    queryMenuItem.setText(getResourceConverter().getFormattedString("workbench.new.MDXQuery.menuitem",
            "{0} MDX", Integer.toString(windowMenuMapIndex)));
    queryMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            try {
                if (jf.isIcon()) {
                    jf.setIcon(false);
                } else {
                    jf.setSelected(true);
                }
            } catch (Exception ex) {
                LOGGER.error("queryMenuItem", ex);
            }
        }
    });

    // disable mdx frame close operation to provide our handler
    // to remove frame object from mdxframeset before closing
    jf.setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);

    jf.addInternalFrameListener(new InternalFrameAdapter() {
        public void internalFrameClosing(InternalFrameEvent e) {
            mdxWindows.remove(jf);
            jf.dispose();
            // follow this by removing file from schemaWindowMap
            windowMenu.remove(queryMenuItem);
            return;
        }
    });

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

    qp.setMenuItem(queryMenuItem);
    qp.setSchemaWindowMap(schemaWindowMap);
    qp.setWindowMenuIndex(windowMenuMapIndex++);

    if (schemaMenuItem != null) {
        qp.initConnection(schemaMenuItem.getText());
    } else {
        JOptionPane.showMessageDialog(this,
                getResourceConverter().getString("workbench.new.MDXQuery.no.selection",
                        "No Mondrian connection. Select a Schema to connect."),
                getResourceConverter().getString("workbench.new.MDXQuery.no.selection.title", "Alert"),
                JOptionPane.WARNING_MESSAGE);
    }
}

From source file:mondrian.gui.Workbench.java

private void newJDBCExplorerMenuItemActionPerformed(ActionEvent evt) {
    try {//  www  . j ava  2  s.c o m
        if (jdbcMetaData == null) {
            getNewJdbcMetadata();
        }

        final JInternalFrame jf = new JInternalFrame();

        jf.setTitle(getResourceConverter().getFormattedString("workbench.new.JDBCExplorer.title",
                "JDBC Explorer - {0} {1}", jdbcMetaData.getDatabaseProductName(),
                jdbcMetaData.getJdbcConnectionUrl()));
        getNewJdbcMetadata();

        JdbcExplorer jdbce = new JdbcExplorer(jdbcMetaData, this);

        jf.getContentPane().add(jdbce);
        jf.setBounds(0, 0, 500, 480);
        jf.setClosable(true);
        jf.setIconifiable(true);
        jf.setMaximizable(true);
        jf.setResizable(true);
        jf.setVisible(true);

        // create jdbc menu item
        final javax.swing.JMenuItem jdbcMenuItem = new javax.swing.JMenuItem();
        jdbcMenuItem.setText(getResourceConverter().getFormattedString("workbench.new.JDBCExplorer.menuitem",
                "{0} JDBC Explorer", Integer.toString(windowMenuMapIndex++)));
        jdbcMenuItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                try {
                    if (jf.isIcon()) {
                        jf.setIcon(false);
                    } else {
                        jf.setSelected(true);
                    }
                } catch (Exception ex) {
                    LOGGER.error("queryMenuItem", ex);
                }
            }
        });

        jf.addInternalFrameListener(new InternalFrameAdapter() {
            public void internalFrameClosing(InternalFrameEvent e) {
                jdbcWindows.remove(jf);
                jf.dispose();
                // follow this by removing file from schemaWindowMap
                windowMenu.remove(jdbcMenuItem);
                return;
            }
        });

        desktopPane.add(jf);
        jf.setVisible(true);
        jf.show();

        try {
            jf.setSelected(true);
        } catch (Exception ex) {
            // do nothing
            LOGGER.error("newJDBCExplorerMenuItemActionPerformed.setSelected", ex);
        }

        jdbcWindows.add(jf);

        windowMenu.add(jdbcMenuItem, -1);
        windowMenu.add(jSeparator3, -1);
        windowMenu.add(cascadeMenuItem, -1);
        windowMenu.add(tileMenuItem, -1);
        windowMenu.add(minimizeMenuItem, -1);
        windowMenu.add(maximizeMenuItem, -1);
        windowMenu.add(closeAllMenuItem, -1);
    } catch (Exception ex) {
        JOptionPane.showMessageDialog(this,
                getResourceConverter().getFormattedString("workbench.new.JDBCExplorer.exception",
                        "Database connection not successful.\n{0}", ex.getLocalizedMessage()),
                getResourceConverter().getString("workbench.new.JDBCExplorer.exception.title",
                        "Database Connection Error"),
                JOptionPane.ERROR_MESSAGE);
        LOGGER.error("newJDBCExplorerMenuItemActionPerformed", ex);
    }
}

From source file:mondrian.gui.Workbench.java

private void saveAsMenuItemActionPerformed(ActionEvent evt) {
    JInternalFrame jf = desktopPane.getSelectedFrame();

    if (jf != null && jf.getContentPane().getComponent(0) instanceof SchemaExplorer) {
        SchemaExplorer se = (SchemaExplorer) jf.getContentPane().getComponent(0);
        java.io.File schemaFile = se.getSchemaFile();
        java.io.File oldSchemaFile = schemaFile;
        java.io.File suggSchemaFile = new File(
                schemaFile == null ? se.getSchema().name.trim() + ".xml" : schemaFile.getName());
        MondrianGuiDef.Schema schema = se.getSchema();
        JFileChooser jfc = new JFileChooser();
        MondrianProperties.instance();/*from  w  w w.  j  a v a  2 s  .  co  m*/

        jfc.setSelectedFile(suggSchemaFile);

        if (!isSchemaValid(schema)) {
            // the schema would not be re-loadable.  Abort save.
            return;
        }

        if (jfc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
            try {
                schemaFile = jfc.getSelectedFile();
                if (!oldSchemaFile.equals(schemaFile) && schemaFile.exists()) { // new file already exists, check for overwrite
                    int answer = JOptionPane.showConfirmDialog(null,
                            getResourceConverter().getFormattedString("workbench.saveAs.schema.confirm",
                                    "{0} schema file already exists. Do you want to replace it?",
                                    schemaFile.getAbsolutePath()),
                            getResourceConverter().getString("workbench.saveAs.schema.confirm.title",
                                    "Save As"),
                            JOptionPane.YES_NO_OPTION);
                    if (answer == 1) { //  no=1 ; yes=0
                        return;
                    }
                }

                if (se.isNewFile() && !oldSchemaFile.equals(schemaFile)) {
                    oldSchemaFile.delete();
                }

                if (se.isNewFile()) {
                    se.setNewFile(false);
                }
                se.setDirty(false);
                se.setDirtyFlag(false);

                XMLOutput out = new XMLOutput(new java.io.FileWriter(jfc.getSelectedFile()));
                out.setAlwaysQuoteCData(true);
                out.setIndentString("  ");
                schema.displayXML(out);
                se.setSchemaFile(schemaFile);
                se.setTitle(); // sets title of iframe
                setLastUsed(jfc.getSelectedFile().getName(), jfc.getSelectedFile().toURI().toURL().toString());

                // Update menu item with new file name, then update catalog
                // list for mdx queries
                JMenuItem sMenuItem = schemaWindowMap.get(jf);
                String mtexttokens[] = sMenuItem.getText().split(" ");
                sMenuItem.setText(mtexttokens[0] + " " + se.getSchemaFile().getName());
                // Schema menu item updated, now update mdx query windows
                // with updated catalog list.
                updateMDXCatalogList();
            } catch (Exception ex) {
                LOGGER.error(ex);
            }
        }
    }
}

From source file:mondrian.gui.Workbench.java

private void openSchemaFrame(File file, boolean newFile) {
    try {//from w ww  . j av a2 s . c o m
        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));
    }
}