private void processEditors(JsArray<JsEditor> editors) { if (editors != null) { for (int i = 0; i < editors.length(); i++) { JsEditor jsEditor = editors.get(i); Editor e = Editor.valueOf(jsEditor.getName()); if (e == null) { throw new IllegalArgumentException( "Unable to find editor name = '" + jsEditor.getName() + "'"); } if (jsEditor.getFormat() != null) { e.setAttribute("format", jsEditor.getFormat()); } e.setStyleName(jsEditor.getStyleName()); } } }
private void addSchema(Database database, JsDatabase meta) { if (meta == null) { throw new IllegalArgumentException("Meta is null."); } Type[] types = new Type[meta.getTypes().length()]; for (int i = 0; i < types.length; i++) { JsType jsType = meta.getTypes().get(i); Type type = new Type(jsType.getName()); type.setEditor(Editor.valueOf(jsType.getEditor())); Operator[] ops = new Operator[jsType.getOperators().length()]; for (int j = 0; j < ops.length; j++) { JsOperator jsOp = jsType.getOperators().get(j); Operator op = new Operator(jsOp.getName()); op.setLabel(jsOp.getLabel()); String cardName = jsOp.getCardinality(); if (cardName != null) { op.setCardinality(Cardinality.valueOf(cardName)); } ops[j] = op; } type.setOperators(ops); types[i] = type; type.setStyleName(jsType.getStyleName()); } database.setTypes(types); for (int i = 0; i < meta.getTables().length(); i++) { JsTable jst = meta.getTables().get(i); Table t = new Table(jst.getName()); t.setLabel(jst.getLabel()); for (int j = 0; j < jst.getColumns().length(); j++) { JsColumn jsColumn = jst.getColumns().get(j); Column c = new Column(jsColumn.getName(), database.getTypeByName(jsColumn.getType())); c.setLabel(jsColumn.getLabel()); if (jsColumn.getEditor() != null) { c.setEditor(Editor.valueOf(jsColumn.getEditor())); } c.setStyleName(jsColumn.getStyleName()); t.add(c); } database.getMainSchema().add(t); } for (int i = 0; i < meta.getTables().length(); i++) { JsTable jst = meta.getTables().get(i); Table pkTable = database.getMainSchema().findTableOrView(jst.getName()); JsArray<JsFk> fks = jst.getFks(); for (int j = 0; j < fks.length(); j++) { JsFk jsfk = fks.get(j); Table fkTable = database.getMainSchema().findTableOrView(jsfk.getFkTableName()); ConstraintReferential fk = new ConstraintReferential(jsfk.getName(), pkTable); fk.setLabel(jsfk.getLabel()); fk.setRefTable(fkTable); fk.setColumns(createColumns(pkTable, jsfk.getPkColumnNames())); fk.setRefColumns(createColumns(fkTable, jsfk.getFkColumnNames())); pkTable.add(fk); ConstraintReferential fkr = new ConstraintReferential(jsfk.getName() + ".reverse", fkTable); fkr.setLabel(jsfk.getReverseLabel()); fkr.setRefTable(pkTable); fkr.setColumns(createColumns(fkTable, jsfk.getFkColumnNames())); // XXX // already // done // this fkr.setRefColumns(createColumns(pkTable, jsfk.getPkColumnNames())); // XXX // already // done // this fkTable.add(fkr); } } }