Object[] values = { new ComboItem("Scalability", ScalabilityXSociety.class), new ComboItem("ABC", ABCSociety.class) }; Object answer = JOptionPane.showInputDialog(this, "Select Society Type", "Select Society", JOptionPane.QUESTION_MESSAGE, null, values, "ScalabilityX"); if (answer instanceof ComboItem) { ComboItem item = (ComboItem) answer; String name = societyNames.generateName(item.name); while (true) { name = (String) JOptionPane.showInputDialog(this, "Enter Society Name", "Name Society", JOptionPane.QUESTION_MESSAGE, null, null, name); if (name == null) return null; if (!societyNames.contains(name)) break; int ok = JOptionPane.showConfirmDialog(this, "Use an unique name", "Society Name Not Unique", JOptionPane.OK_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE); if (ok != JOptionPane.OK_OPTION) return null; } try { Constructor constructor = item.cls.getConstructor(constructorArgTypes); SocietyComponent sc = (SocietyComponent) constructor.newInstance(new String[] {name}); sc.initProperties(); DefaultMutableTreeNode newNode = addSocietyToWorkspace(sc, node); workspace.setSelection(newNode); return newNode; } catch (Exception e) { e.printStackTrace(); return null; } }
Object[] values = { new ComboItem("Scalability", ScalabilityXSociety.class), new ComboItem("ABC", ABCSociety.class) }; Object answer = JOptionPane.showInputDialog(this, "Select Society Type", "Select Society", JOptionPane.QUESTION_MESSAGE, null, values, "ScalabilityX"); if (answer instanceof ComboItem) { ComboItem item = (ComboItem) answer; String name = societyNames.generateName(item.name); while (true) { name = (String) JOptionPane.showInputDialog(this, "Enter Society Name", "Name Society", JOptionPane.QUESTION_MESSAGE, null, null, name); if (name == null) return null; if (!societyNames.contains(name)) break; int ok = JOptionPane.showConfirmDialog(this, "Use an unique name", "Society Name Not Unique", JOptionPane.OK_CANCEL_OPTION, JOptionPane.ERROR_MESSAGE); if (ok != JOptionPane.OK_OPTION) return null; } try { Constructor constructor = item.cls.getConstructor(constructorArgTypes); SocietyComponent sc = (SocietyComponent) constructor.newInstance(new String[] {name}); sc.initProperties(); DefaultMutableTreeNode newNode = addSocietyToWorkspace(sc, node); workspace.setSelection(newNode); return newNode; } catch (Exception e) { e.printStackTrace();
    private DefaultMutableTreeNode newSociety(DefaultMutableTreeNode node) {        Object[] values = {            new ComboItem("Scalability", ScalabilityXSociety.class),	    new ComboItem("ABC", ABCSociety.class)        };        Object answer =            JOptionPane.showInputDialog(this, "Select Society Type",                                        "Select Society",                                        JOptionPane.QUESTION_MESSAGE,                                        null,                                        values,                                        "ScalabilityX");        if (answer instanceof ComboItem) {            ComboItem item = (ComboItem) answer;            String name = societyNames.generateName(item.name);            while (true) {                name = (String) JOptionPane.showInputDialog(this, "Enter Society Name",                                                            "Name Society",                                                            JOptionPane.QUESTION_MESSAGE,                                                            null, null,                                                            name);                if (name == null) return null;                if (!societyNames.contains(name)) break;                int ok = JOptionPane.showConfirmDialog(this,                                                       "Use an unique name",                                                       "Society Name Not Unique",                                                       JOptionPane.OK_CANCEL_OPTION,                                                       JOptionPane.ERROR_MESSAGE);                if (ok != JOptionPane.OK_OPTION) return null;            }            try {                Constructor constructor = item.cls.getConstructor(constructorArgTypes);                SocietyComponent sc = (SocietyComponent) constructor.newInstance(new String[] {name});                sc.initProperties();		DefaultMutableTreeNode newNode =		  addSocietyToWorkspace(sc, node);		workspace.setSelection(newNode);		return newNode;            } catch (Exception e) {                e.printStackTrace();		return null;            }        }	return null;    }