/** Creates the UI from the EditPlugins the inspection of the edited object found out. */ private void createUI() { try { panel.removeAll(); Set<GSMethod> set = this.methods.keySet(); Map<GSMethod, EditPlugin> localMethods = new HashMap<GSMethod, EditPlugin>(); Iterator<GSMethod> iter = set.iterator(); List<GSMethod> sortedMethods = new ArrayList<GSMethod>(); while (iter.hasNext()) { GSMethod meth = iter.next(); EditPlugin plugin = this.methods.get(meth); localMethods.put(meth, plugin); } set = localMethods.keySet(); int size = set.size(); for (int i = 0; i < size; i++) { set = localMethods.keySet(); iter = set.iterator(); GSMethod minMethod = null; while (iter.hasNext()) { GSMethod method = iter.next(); if (minMethod == null) minMethod = method; if (method.methodId <= minMethod.methodId) minMethod = method; } localMethods.remove(minMethod); sortedMethods.add(minMethod); } iter = sortedMethods.iterator(); while (iter.hasNext()) { GSMethod method = iter.next(); EditPlugin plugin = methods.get(method); panel.add(plugin.getView()); } } catch (Exception e) { JOptionPane.showMessageDialog( null, "Error: " + e.toString(), "Error!", JOptionPane.ERROR_MESSAGE); } }
/** * Inspects the currently edited object and clones plugins if they are needed. * * @throws EClassEditorMissing Will be thrown if there is no EditPlugin registered for a certain * class but the currently edited object has an attribute of that class. Note that this won' t * happen in this implementation because by default an editor for missing classes is * registered. */ private void inspectEditedObject() throws EClassEditorMissing { Method[] tempMethods = editedObject.getClass().getDeclaredMethods(); // methods = new HashMap<GSMethod, EditPlugin>(); methods = new HashMap<GSMethod, EditPlugin>(); Map<String, GSMethod> map = this.editedObject.getAllAttribs(); Set<String> set = map.keySet(); Iterator<String> iter = set.iterator(); while (iter.hasNext()) { String key = iter.next(); GSMethod x = map.get(key); EditPlugin plug = this.getNewPlugin(x.getMethod.getReturnType()); if (!x.show) continue; if (plug == null) plug = this.getNewPlugin(Object.class); plug.setName(key); try { Object obj = null; try { obj = x.getMethod.invoke(this.editedObject, new Object[] {}); } catch (Exception e) { obj = null; } plug.setValue(obj); } catch (Exception e) { JOptionPane.showMessageDialog( null, "Error: " + e.toString(), "Error!", JOptionPane.ERROR_MESSAGE); } if (x instanceof GSMethodForeign) { EditPlugin original = plug; plug = new ForeignKeyEditPlugin(); ((ForeignKeyEditPlugin) plug).setEditPlugin(original); ((ForeignKeyEditPlugin) plug).setEditedTable(((GSMethodForeign) x).tableName); ((ForeignKeyEditPlugin) plug).setEditedAttrib(((GSMethodForeign) x).attribName); ((ForeignKeyEditPlugin) plug).setEditedClass(((GSMethodForeign) x).objectClass); ((ForeignKeyEditPlugin) plug).setParentFrame(this.parentFrame); } if (x instanceof GSMethodPrimary) { // do nothing } methods.put(x, plug); } }