Search in sources :

Example 21 with TreeTableNode

use of com.ramussoft.gui.qualifier.table.TreeTableNode in project ramus by Vitaliy-Yakovchuk.

the class QualifierView method refreshActions.

@Override
protected void refreshActions() {
    super.refreshActions();
    TreePath selectionPath = table.getTreeSelectionModel().getSelectionPath();
    boolean anySelected = selectionPath != null;
    qualifierPreferenciesAction.setEnabled(anySelected);
    Row sRow = null;
    if (selectionPath != null)
        sRow = ((TreeTableNode) selectionPath.getLastPathComponent()).getRow();
    if (sRow == null)
        convertQualifierToElementsAction.setEnabled(false);
    else {
        if ((sRow.getChildCount() == 0) || (table.getTreeSelectionModel().getSelectionPaths().length > 1))
            convertQualifierToElementsAction.setEnabled(false);
        else
            convertQualifierToElementsAction.setEnabled(canDeleteLastLeveleOfQualifiers(sRow, qAttribute));
    }
    openQualifier.setEnabled(anySelected && sRow != null && sRow.getChildCount() == 0);
    if (deleteElementAction.isEnabled()) {
        TreePath[] paths = table.getTreeSelectionModel().getSelectionPaths();
        boolean e = true;
        for (TreePath path : paths) {
            Row row = ((TreeTableNode) path.getLastPathComponent()).getRow();
            if (engine.getElement(row.getElementId()) == null)
                row = null;
            if (row == null) {
                e = false;
                break;
            }
            if (row.getChildCount() > 0) {
                e = false;
                break;
            }
            Long attribute = (Long) row.getAttribute(qAttribute);
            if ((attribute != null) && (!accessRules.canDeleteQualifier(attribute))) {
                e = false;
                break;
            }
        }
        deleteElementAction.setEnabled(e);
    }
}
Also used : TreePath(javax.swing.tree.TreePath) TreeTableNode(com.ramussoft.gui.qualifier.table.TreeTableNode) Row(com.ramussoft.database.common.Row) RootRow(com.ramussoft.database.common.RowSet.RootRow)

Example 22 with TreeTableNode

use of com.ramussoft.gui.qualifier.table.TreeTableNode 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();
}
Also used : TreeTableNode(com.ramussoft.gui.qualifier.table.TreeTableNode) Attribute(com.ramussoft.common.Attribute) RowSet(com.ramussoft.database.common.RowSet) Workbook(org.apache.poi.ss.usermodel.Workbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Font(org.apache.poi.ss.usermodel.Font) Date(java.util.Date) RowTreeTableModel(com.ramussoft.gui.qualifier.table.RowTreeTableModel) FileOutputStream(java.io.FileOutputStream) CellStyle(org.apache.poi.ss.usermodel.CellStyle) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet) Cell(org.apache.poi.ss.usermodel.Cell)

Aggregations

TreeTableNode (com.ramussoft.gui.qualifier.table.TreeTableNode)22 Row (com.ramussoft.database.common.Row)20 TreePath (javax.swing.tree.TreePath)10 Engine (com.ramussoft.common.Engine)7 Attribute (com.ramussoft.common.Attribute)6 ArrayList (java.util.ArrayList)6 RootRow (com.ramussoft.database.common.RowSet.RootRow)5 RowTreeTable (com.ramussoft.gui.qualifier.table.RowTreeTable)5 AccessRules (com.ramussoft.common.AccessRules)4 Qualifier (com.ramussoft.common.Qualifier)3 Journaled (com.ramussoft.common.journal.Journaled)3 RowRootCreater (com.ramussoft.gui.qualifier.table.RowRootCreater)3 RowTreeTableComponent (com.ramussoft.gui.qualifier.table.RowTreeTableComponent)3 SelectionEvent (com.ramussoft.gui.qualifier.table.event.SelectionEvent)3 ActionEvent (java.awt.event.ActionEvent)3 MouseAdapter (java.awt.event.MouseAdapter)3 MouseEvent (java.awt.event.MouseEvent)3 AbstractAction (javax.swing.AbstractAction)3 RowNode (com.ramussoft.gui.qualifier.table.RowNode)2 RowTreeTableModel (com.ramussoft.gui.qualifier.table.RowTreeTableModel)2