Object[] values = { new ComboItem("Some Metric", SomeMetric.class), new ComboItem("Mo Metric", MoMetric.class) }; Object answer = JOptionPane.showInputDialog(this, "Select Metric Type", "Select Metric", JOptionPane.QUESTION_MESSAGE, null, values, "Mo Metric"); if (answer instanceof ComboItem) { ComboItem item = (ComboItem) answer; String name = metricNames.generateName(item.name); while (true) { name = (String) JOptionPane.showInputDialog(this, "Enter Metric Name", "Name Metric", JOptionPane.QUESTION_MESSAGE, null, null, name); if (name == null) return; if (!metricNames.contains(name)) break; int ok = JOptionPane.showConfirmDialog(this, "Use an unique name", "Metric Name Not Unique", JOptionPane.OK_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE); if (ok != JOptionPane.OK_OPTION) return; } try { Constructor constructor = item.cls.getConstructor(constructorArgTypes); Metric metric = (Metric) constructor.newInstance(new String[] {name}); DefaultMutableTreeNode newNode = addMetricToWorkspace(metric, node); workspace.setSelection(newNode); } catch (Exception e) { e.printStackTrace(); } }
Object[] values = { new ComboItem("Some Metric", SomeMetric.class), new ComboItem("Mo Metric", MoMetric.class) }; Object answer = JOptionPane.showInputDialog(this, "Select Metric Type", "Select Metric", JOptionPane.QUESTION_MESSAGE, null, values, "Mo Metric"); if (answer instanceof ComboItem) { ComboItem item = (ComboItem) answer; String name = metricNames.generateName(item.name); while (true) { name = (String) JOptionPane.showInputDialog(this, "Enter Metric Name", "Name Metric", JOptionPane.QUESTION_MESSAGE, null, null, name); if (name == null) return; if (!metricNames.contains(name)) break; int ok = JOptionPane.showConfirmDialog(this, "Use an unique name", "Metric Name Not Unique", JOptionPane.OK_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE); if (ok != JOptionPane.OK_OPTION) return; } try { Constructor constructor = item.cls.getConstructor(constructorArgTypes); Metric metric = (Metric) constructor.newInstance(new String[] {name}); DefaultMutableTreeNode newNode = addMetricToWorkspace(metric, node); workspace.setSelection(newNode); } catch (Exception e) { e.printStackTrace(); }
    private void newMetric(DefaultMutableTreeNode node) {        Object[] values = {            new ComboItem("Some Metric", SomeMetric.class),            new ComboItem("Mo Metric", MoMetric.class)        };        Object answer =            JOptionPane.showInputDialog(this, "Select Metric Type",                                        "Select Metric",                                        JOptionPane.QUESTION_MESSAGE,                                        null,                                        values,                                        "Mo Metric");        if (answer instanceof ComboItem) {            ComboItem item = (ComboItem) answer;            String name = metricNames.generateName(item.name);            while (true) {                name = (String) JOptionPane.showInputDialog(this, "Enter Metric Name",                                                            "Name Metric",                                                            JOptionPane.QUESTION_MESSAGE,                                                            null, null,                                                            name);                if (name == null) return;                if (!metricNames.contains(name)) break;                int ok = JOptionPane.showConfirmDialog(this,                                                       "Use an unique name",                                                       "Metric Name Not Unique",                                                       JOptionPane.OK_CANCEL_OPTION,                                                       JOptionPane.ERROR_MESSAGE);                if (ok != JOptionPane.OK_OPTION) return;            }            try {                Constructor constructor = item.cls.getConstructor(constructorArgTypes);                Metric metric =                    (Metric) constructor.newInstance(new String[] {name});		DefaultMutableTreeNode newNode =		  addMetricToWorkspace(metric, node);		workspace.setSelection(newNode);            } catch (Exception e) {                e.printStackTrace();            }        }    }