Package jsynoptic.parser

Examples of jsynoptic.parser.ExpressionParser


                    JOptionPane.showMessageDialog(JSynoptic.gui.getOwner(),resources.getString("PleaseEnterAMathematicalExpression"),resources.getString("Error"),JOptionPane.ERROR_MESSAGE);
                    return;
                }
                ExpressionNode node = null;
                try {
                    ExpressionParser ep = new ExpressionParser(exp);
                    // Add the data sources as variables
                    // start by looping through collections
                    Set collections = DataSourcePool.global.dataSourceCollections();
                    for (Iterator it = collections.iterator(); it.hasNext(); ) {
                        Collection c = (Collection)it.next();
                        for (Iterator it2 = c.iterator(); it2.hasNext();) addVariable(ep, it2.next());
                    }
                    // also add sources
                    Set sources = DataSourcePool.global.dataSources();
                    for (Iterator it = sources.iterator(); it.hasNext();) addVariable(ep, it.next());
                    // Add known plugins => may bring in more mathematical functions
                    for (Iterator it = Run.plugins.iterator(); it.hasNext();) ep.addClass(it.next().getClass());
                    node = ep.parse();
                } catch (ParseException pe) {
                    // Also catches duplicate variable names
                    JOptionPane.showMessageDialog(JSynoptic.gui.getOwner(),pe.getLocalizedMessage(),resources.getString("InvalidExpression"),JOptionPane.ERROR_MESSAGE);
                    return;
                } catch (Error err) {
                    JOptionPane.showMessageDialog(JSynoptic.gui.getOwner(),err.getLocalizedMessage(),resources.getString("InvalidExpression"),JOptionPane.ERROR_MESSAGE);
                    return;
                }
                // Now we have a correct node, ready to evaluate()
                // Create a data source
                boolean newSource = true;
                // Check if the source exists, and in this case change the expression on the fly
                for (Iterator it = DataSourcePool.global.dataSources().iterator(); it.hasNext(); ) {
                    Object o = it.next();
                    if (!(o instanceof ExpressionDataSource)) continue;
                    ExpressionDataSource ds = (ExpressionDataSource)o;
                    if (name.equals(DataInfo.getLabel(ds)) || name.equals(DataInfo.getAlias(ds))) {
                        ds.changeExpression(exp, node);
                        newSource = false;
                        ExpressionPanel.this.sourceTree.setSelectedValue(ds);
                        TreeNode tn = (TreeNode)(ExpressionPanel.this.sourceTree.getSelectionPath().getLastPathComponent());
                        ((DefaultTreeModel)(ExpressionPanel.this.sourceTree.getModel())).nodeChanged(tn);
                        break;
                    }
                }
                if (newSource) {
                    ExpressionDataSource eds = new ExpressionDataSource(new DataInfo(name, name, exp), node);
                    DataSourcePool.global.addDataSource(eds);
                    ExpressionPanel.this.sourceTree.setSelectedValue(eds);
                }
            }

            private void addVariable(ExpressionParser ep, Object object) {
                if (object==null) return;
                if (!(object instanceof DataSource)) return;
                String alias = DataInfo.getAlias(object);
                if (alias!=null) ep.addVariable(new VariableAssociation((DataSource)object, alias));
                else ep.addVariable(new VariableAssociation((DataSource)object, DataInfo.getLabel(object)));
            }
        });

/*        delExp.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
View Full Code Here


                }
            }
        }
        ExpressionNode node = null;
        try {
            ExpressionParser ep = new ExpressionParser(expression);
            // Add the data sources as variables, once conflicts are resolved
            for (int i = 0; i < clm.size(); ++i) {
                VariableConflict vc = (VariableConflict) clm.get(i);
                ep.addVariable(new VariableAssociation(vc.ds, vc.var));
            }
            // Add known plugins => may bring in more mathematical functions
            for (Iterator it = Run.plugins.iterator(); it.hasNext();) {
                ep.addClass(it.next().getClass());
            }
            node = ep.parse();
        } catch (ParseException pe) {
            // Also catches duplicate variable names
            JOptionPane.showMessageDialog(JSynoptic.gui.getOwner(), pe.getLocalizedMessage(), resources
                    .getString("CantRestoreExpression")
                    + expression, JOptionPane.ERROR_MESSAGE);
View Full Code Here

TOP

Related Classes of jsynoptic.parser.ExpressionParser

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.