use of com.ramussoft.database.common.RowSet in project ramus by Vitaliy-Yakovchuk.
the class SelectableTableView method selectRows.
public void selectRows(List<Long> rows) {
RowSet set = component.getRowSet();
RowTreeTableModel model = component.getModel();
for (Long id : rows) {
Row row = set.findRow(id);
if (row != null)
model.setSelectedRow(row, true);
}
}
use of com.ramussoft.database.common.RowSet in project ramus by Vitaliy-Yakovchuk.
the class TableCellEditorFactory method createModelEditor.
private TableCellEditor createModelEditor() {
Qualifier qualifier = getModelTree(engine);
Attribute nameAttribute = StandardAttributesPlugin.getAttributeNameAttribute(engine);
RowSet rowSet = new RowSet(engine, qualifier, new Attribute[] { nameAttribute }, null, true);
OtherElementTableCellEditor editor = new OtherElementTableCellEditor(rowSet, nameAttribute, framework, null) {
/**
*/
private static final long serialVersionUID = -5820017882593141555L;
private OtherElementListModel model;
private void updateValue() {
if (list.getSelectedIndex() == 0)
value = null;
else if (list.getSelectedIndex() == 1)
value = "[ALL MODELS]";
else {
if (model.checked.size() == 0) {
value = model.wrappers[list.getSelectedIndex() - 2].row.getName();
} else {
StringBuffer sb = null;
for (PopupRowWrapper w : model.checked.keySet()) {
if (sb == null)
sb = new StringBuffer(w.row.getName());
else {
sb.append(com.ramussoft.report.editor.xml.Attribute.QUALIFIER_DELIMETER);
sb.append(w.row.getName());
}
}
value = sb.toString();
}
}
}
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int rowIndex, int columnIndex) {
try {
this.table = table;
if (value instanceof String) {
Row r = rowSet.findRow((String) value);
if (r != null) {
return super.getTableCellEditorComponent(table, value, isSelected, rowIndex, columnIndex);
} else {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
codeField.selectAll();
codeField.requestFocus();
}
});
return component;
}
}
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
codeField.selectAll();
codeField.requestFocus();
}
});
return super.getTableCellEditorComponent(table, value, isSelected, rowIndex, columnIndex);
} finally {
this.value = value;
}
}
protected JPopupMenu getMenu(Attribute attribute) {
if (menu == null) {
menu = new JPopupMenu(attribute.getName());
menu.setMaximumSize(new Dimension(600, 500));
JScrollPane pane = new JScrollPane();
List<Row> allRows = rowSet.getAllRows();
wrappers = new PopupRowWrapper[allRows.size()];
for (int i = 0; i < wrappers.length; i++) {
wrappers[i] = new PopupRowWrapper(allRows.get(i), attribute);
}
model = new OtherElementListModel(wrappers);
list = new JList(model) {
/**
*/
private static final long serialVersionUID = 3924839890645563320L;
CheckCellRenderer cellRenderer;
public ListCellRenderer getCellRenderer() {
if (cellRenderer == null)
cellRenderer = new CheckCellRenderer(model, super.getCellRenderer());
return cellRenderer;
}
};
Dimension size = list.getPreferredSize();
if (size.width > 600)
list.setPreferredSize(new Dimension(600, size.height));
if (value == null)
list.setSelectedIndex(0);
else {
List<String> slist = new ArrayList<String>();
String val = ((String) value);
StringTokenizer st = new StringTokenizer(val, com.ramussoft.report.editor.xml.Attribute.QUALIFIER_DELIMETER);
slist.add(val);
while (st.hasMoreTokens()) slist.add(st.nextToken());
if ("[ALL MODELS]".equals(val))
list.setSelectedIndex(1);
else {
List<Integer> seleted = new ArrayList<Integer>();
for (int i = 0; i < wrappers.length; i++) {
if (slist.contains(wrappers[i].row.getName())) {
model.select(wrappers[i]);
seleted.add(i + 2);
}
}
int[] is = new int[seleted.size()];
for (int i = 0; i < is.length; i++) is[i] = seleted.get(i);
if (is.length > 0)
list.setSelectedIndices(is);
}
}
list.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
list.ensureIndexIsVisible(list.getSelectedIndex());
}
});
list.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
private boolean rec = false;
@Override
public void valueChanged(ListSelectionEvent e) {
if (rec)
return;
rec = true;
int index = list.getSelectedIndex();
PopupRowWrapper wrapper = null;
if (index < 0)
return;
updateValue();
if (index == 0)
value = null;
else if (index > 1) {
wrapper = wrappers[index - 2];
}
if (updateFields) {
codeField.setBackground(fieldDefaultBackground);
valueField.setBackground(fieldDefaultBackground);
if (wrapper == null) {
codeField.setText("");
valueField.setText("");
} else {
codeField.setText(wrapper.code);
codeField.setCaretPosition(0);
valueField.setText(wrapper.value);
valueField.setCaretPosition(0);
}
}
rec = false;
}
});
list.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getX() <= 20 && e.getClickCount() < 2) {
int index = list.getSelectedIndex();
if (index > 1) {
index -= 2;
model.select(wrappers[index]);
updateValue();
list.repaint();
return;
}
}
updateValue();
stopCellEditing();
}
});
InputMap inputMap = list.getInputMap();
KeyStroke[] allKeys = inputMap.allKeys();
for (Object actionName : actionsToReplace) {
for (KeyStroke stroke : allKeys) {
Object value = inputMap.get(stroke);
if (actionName.equals(value)) {
codeField.getInputMap().put(stroke, actionName);
valueField.getInputMap().put(stroke, actionName);
final Action source = list.getActionMap().get(actionName);
if (source != null) {
Action action = new AbstractAction() {
/**
*/
private static final long serialVersionUID = 4806926801192964440L;
@Override
public void actionPerformed(ActionEvent e) {
if (list != null) {
updateFields = true;
e.setSource(list);
source.actionPerformed(e);
updateFields = false;
}
}
};
valueField.getActionMap().put(actionName, action);
codeField.getActionMap().put(actionName, action);
}
}
}
}
pane.setViewportView(list);
menu.add(pane);
menu.pack();
}
return menu;
}
@Override
protected void edit() {
if (menu != null) {
menu.setVisible(false);
menu = null;
}
final SelectableTableView view = new SelectableTableView(framework, engine, framework.getAccessRules(), rowSet.getQualifier()) {
@Override
public String getPropertiesPrefix() {
return "xml_edit";
}
};
JComponent rc = view.createComponent();
final RowTreeTableComponent component = view.getComponent();
component.getTable().setComponentPopupMenu(null);
component.getTable().setTableHeader(null);
List<String> slist = new ArrayList<String>();
String val = ((String) value);
if (val != null) {
StringTokenizer st = new StringTokenizer(val, com.ramussoft.report.editor.xml.Attribute.QUALIFIER_DELIMETER);
slist.add(val);
while (st.hasMoreTokens()) slist.add(st.nextToken());
for (Row row : component.getRowSet().getAllRows()) if (slist.contains(row.getName()))
component.getModel().setSelectedRow(row, true);
}
view.setSelectType(SelectType.CHECK);
BaseDialog dialog = new BaseDialog(framework.getMainFrame()) {
/**
*/
private static final long serialVersionUID = -4426170644933177805L;
@Override
protected void onOk() {
List<Row> rows = view.getSelectedRows();
if (rows.size() == 0)
value = null;
else {
StringBuffer sb = null;
for (Row w : rows) {
if (sb == null)
sb = new StringBuffer(w.getName());
else {
sb.append(com.ramussoft.report.editor.xml.Attribute.QUALIFIER_DELIMETER);
sb.append(w.getName());
}
}
value = sb.toString();
}
stopCellEditing();
super.onOk();
}
};
dialog.setMainPane(rc);
dialog.setTitle(ReportResourceManager.getString("ReportAttribute.model"));
dialog.setLocationRelativeTo(null);
Options.loadOptions("IDEF0_models", dialog);
dialog.setModal(true);
dialog.setVisible(true);
Options.saveOptions("IDEF0_models", dialog);
try {
view.close();
} catch (Exception e) {
e.printStackTrace();
}
}
};
return editor;
}
use of com.ramussoft.database.common.RowSet in project ramus by Vitaliy-Yakovchuk.
the class Exporter method exportToFile.
public void exportToFile(List<Attribute> attributes, Qualifier qualifier, File file) throws IOException {
Workbook workbook = new HSSFWorkbook();
CellStyle headerStyle;
Font headerFont = workbook.createFont();
headerFont.setBoldweight(Font.BOLDWEIGHT_BOLD);
headerStyle = createBorderedStyle(workbook);
headerStyle.setAlignment(CellStyle.ALIGN_CENTER);
headerStyle.setFillForegroundColor(IndexedColors.LIGHT_CORNFLOWER_BLUE.getIndex());
headerStyle.setFillPattern(CellStyle.SOLID_FOREGROUND);
headerStyle.setFont(headerFont);
CellStyle normalStyle;
normalStyle = createBorderedStyle(workbook);
normalStyle.setAlignment(CellStyle.ALIGN_LEFT);
normalStyle.setWrapText(true);
CellStyle dateStyle = createDateStyle(workbook);
String name = qualifier.getName();
Sheet sheet;
if ((name == null) || (name.equals("")))
sheet = workbook.createSheet();
else
sheet = workbook.createSheet(name);
sheet.setDisplayGridlines(false);
sheet.setPrintGridlines(false);
sheet.setFitToPage(true);
sheet.setHorizontallyCenter(true);
sheet.setAutobreaks(true);
Row headerRow = sheet.createRow(0);
headerRow.setHeightInPoints(12.75f);
for (int i = 0; i < attributes.size(); i++) {
Cell cell = headerRow.createCell(i);
cell.setCellValue(attributes.get(i).getName());
cell.setCellStyle(headerStyle);
}
RowSet rowSet = tableView.getComponent().getRowSet();
RowTreeTableModel model = tableView.getComponent().getModel();
int i = 1;
for (com.ramussoft.database.common.Row row : rowSet.getAllRows()) {
Row cellRow = sheet.createRow(i);
int j = 0;
for (Attribute attribute : attributes) {
if (attribute.getAttributeType().isLight()) {
Cell cell = cellRow.createCell(j);
cell.setCellStyle(normalStyle);
Object object = row.getAttribute(attribute);
if (object != null) {
if (object instanceof Date) {
cell.setCellStyle(dateStyle);
cell.setCellValue((Date) object);
} else {
TreeTableNode node = model.findNode(row);
if (node != null) {
int index = rowSet.getAttributeIndex(attribute) - 1;
if (index >= 00) {
Object object2 = model.getValueAt(node, index);
if (object2 != null)
cell.setCellValue(object2.toString());
}
}
}
}
}
j++;
}
i++;
}
FileOutputStream fileOutputStream = new FileOutputStream(file);
workbook.write(fileOutputStream);
fileOutputStream.close();
}
Aggregations