@Override public Parameter fromXml(XmlPullParser parser) throws XmlPullParserException, IOException { OptionParameter p = new OptionParameter(); int depth = parser.getDepth(); int startdepth = depth; // proceed by one tag (out of option tag) int eventType = parser.nextTag(); while (!((eventType == XmlPullParser.END_TAG) && (depth == startdepth))) { // proceed to the next start tag if (eventType == XmlPullParser.START_TAG) { Parameter parameter = ParameterManager.getInstance().parseXml(parser); String name = parser.getName().trim(); if (name.equalsIgnoreCase("option")) { try { p.addOption(parameter); } catch (SpecializationException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else if (name.equalsIgnoreCase("value")) { String value = parser.nextText(); p.addValue(value); } } eventType = parser.next(); depth = parser.getDepth(); } return p; }
private void addFromReport() { if (Globals.getConnection() == null) { Show.info(I18NSupport.getString("no.data.source.connected")); return; } final ReportParametersPanel panel = new ReportParametersPanel(); panel.setMinimumSize(new Dimension(300, (int) panel.getMinimumSize().getHeight())); BaseDialog dialog = new BaseDialog(panel, I18NSupport.getString("parameter.add.from.report")) { protected boolean ok() { List<QueryParameter> parameters = panel.getSelectedParameters(); if (parameters.size() == 0) { return false; } for (QueryParameter qp : parameters) { if (ParameterManager.getInstance().containsParameter(qp.getName())) { JOptionPane.showMessageDialog( this, I18NSupport.getString("parameter.edit.name.exists.value", qp.getName())); return false; } } return true; } }; panel.setParent(dialog); dialog.pack(); Show.centrateComponent(Globals.getMainFrame(), dialog); dialog.setVisible(true); if (dialog.okPressed()) { for (QueryParameter qp : panel.getSelectedParameters()) { ParameterManager.getInstance().addParameter(qp); } model.addObjects(panel.getSelectedParameters()); } }
private void down() { int[] selectedRows = table.getSelectedRows(); if (selectedRows.length != 1) { Show.info(I18NSupport.getString("parameter.select")); return; } QueryParameter param = (QueryParameter) model.getObjectForRow(selectedRows[0]); ParameterManager.getInstance().moveParameter(param.getName(), false); model.moveObjectDown(selectedRows[0]); }
private void cloneParameter() { int[] selectedRows = table.getSelectedRows(); if (selectedRows.length != 1) { Show.info(I18NSupport.getString("parameter.select")); return; } QueryParameter oldParam = (QueryParameter) model.getObjectForRow(selectedRows[0]); QueryParameter clone = ObjectCloner.silenceDeepCopy(oldParam); clone.setName(clone.getName() + "_c"); ParameterManager.getInstance().addParameter(clone); model.addObject(clone); }
private void add() { if (Globals.getConnection() == null) { Show.info(I18NSupport.getString("no.data.source.connected")); return; } ParameterEditPanel panel = new ParameterEditPanel(null); ParameterEditDialog dlg = new ParameterEditDialog(panel, I18NSupport.getString("add.parameter.title"), true); dlg.pack(); Show.centrateComponent(Globals.getMainFrame(), dlg); dlg.setVisible(true); if (dlg.okPressed() && (dlg.getParameter() != null)) { ParameterManager.getInstance().addParameter(dlg.getParameter()); model.addObject(dlg.getParameter()); } }
private void delete() { int[] selectedRows = table.getSelectedRows(); if (selectedRows.length == 0) { Show.info(I18NSupport.getString("parameter.select")); return; } if (JOptionPane.showConfirmDialog( Globals.getMainFrame(), I18NSupport.getString("parameter.askDelete")) != JOptionPane.OK_OPTION) { return; } for (int i = selectedRows.length - 1; i >= 0; i--) { QueryParameter param = (QueryParameter) model.getObjectForRow(selectedRows[i]); ParameterManager.getInstance().deleteParameter(param); model.deleteObject(selectedRows[i]); } }
private void modify() { int[] selectedRows = table.getSelectedRows(); if (selectedRows.length != 1) { Show.info(I18NSupport.getString("parameter.select")); return; } QueryParameter oldParam = (QueryParameter) model.getObjectForRow(selectedRows[0]); ParameterEditPanel panel = new ParameterEditPanel(oldParam); ParameterEditDialog dlg = new ParameterEditDialog(panel, I18NSupport.getString("modify.parameter.title"), true); dlg.pack(); Show.centrateComponent(Globals.getMainFrame(), dlg); dlg.setVisible(true); if (!dlg.okPressed()) { return; } QueryParameter newParam = dlg.getParameter(); ParameterManager.getInstance().modifyParameter(oldParam, newParam); model.updateObject(selectedRows[0], newParam); }
public class ParametersTableModel extends AbstractTableModel { private final String[] columnNames = { I18NSupport.getString("parameter.name"), I18NSupport.getString("parameter.type") // "Description" }; private List elements = ParameterManager.getInstance().getParameters(); public String getColumnName(int columnIndex) { return columnNames[columnIndex]; } public int getColumnCount() { return columnNames.length; } public int getRowCount() { // this method is called in the constructor so we must test for null if (elements == null) { return 0; } return elements.size(); } @SuppressWarnings("unchecked") public void addObject(Object object) { elements.add(object); fireTableDataChanged(); } @SuppressWarnings("unchecked") public void addObjects(List objects) { elements.addAll(objects); fireTableDataChanged(); } public void deleteObject(int rowIndex) { elements.remove(rowIndex); fireTableDataChanged(); } public void moveObjectUp(int rowIndex) { if (rowIndex > 0) { QueryParameter param = (QueryParameter) elements.get(rowIndex); CollectionUtil.moveItem(elements, param, rowIndex - 1); fireTableDataChanged(); table.setRowSelectionInterval(rowIndex - 1, rowIndex - 1); } } public void moveObjectDown(int rowIndex) { if (rowIndex < elements.size() - 1) { QueryParameter param = (QueryParameter) elements.get(rowIndex); CollectionUtil.moveItem(elements, param, rowIndex + 1); fireTableDataChanged(); table.setRowSelectionInterval(rowIndex + 1, rowIndex + 1); } } @SuppressWarnings("unchecked") public void deleteObjects(List objects) { elements.removeAll(objects); fireTableDataChanged(); } public void clear() { elements.clear(); fireTableDataChanged(); } public Object getObjectForRow(int rowIndex) { return elements.get(rowIndex); } @SuppressWarnings("unchecked") public void updateObject(int row, Object object) { row = table.convertRowIndexToModel(row); elements.set(row, object); fireTableDataChanged(); } public Object getValueAt(int rowIndex, int columnIndex) { QueryParameter row = (QueryParameter) elements.get(rowIndex); switch (columnIndex) { case 0: return row.getName(); case 1: return row.getValueClassName(); // case 2: // return row.getDescription(); default: return null; } } }
public void addParameter(QueryParameter param) { ParameterManager.getInstance().addParameter(param); model.addObject(param); }
public void set(List<QueryParameter> parameters) { ParameterManager.getInstance().clearParameters(); model.clear(); addAll(parameters); }
public void addAll(List<QueryParameter> parameters) { for (QueryParameter param : parameters) { ParameterManager.getInstance().addParameter(param); model.addObject(param); } }
public static FloatParam createManaged(String name, float value, float min, float max) { FloatParam ret = create(name, value, min, max); ParameterManager.add(ret); return ret; }