Search in sources :

Example 1 with CellAdapter

use of com.servoy.j2db.smart.dataui.CellAdapter in project servoy-client by Servoy.

the class FixedJTable method isCellEditable.

/*
	 * @see javax.swing.JTable#isCellEditable(int, int)
	 */
@Override
public boolean isCellEditable(int row, int column) {
    Object o = getCellEditor(row, column);
    if (o instanceof CellAdapter) {
        Component comp = ((CellAdapter) o).getEditor();
        boolean isReadOnlyEditor = (comp instanceof IDelegate) && (((IDelegate) comp).getDelegate() instanceof JEditorPane) && !((JEditorPane) ((IDelegate) comp).getDelegate()).isEditable();
        if ((comp instanceof JButton || comp instanceof JLabel || isReadOnlyEditor) && comp.isEnabled()) {
            return true;
        }
    }
    return super.isCellEditable(row, column);
}
Also used : JEditorPane(javax.swing.JEditorPane) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) EventObject(java.util.EventObject) CellAdapter(com.servoy.j2db.smart.dataui.CellAdapter) Component(java.awt.Component) IDelegate(com.servoy.j2db.util.IDelegate)

Example 2 with CellAdapter

use of com.servoy.j2db.smart.dataui.CellAdapter in project servoy-client by Servoy.

the class TableView method moveColumnInSameGroup.

private boolean moveColumnInSameGroup(TableColumn column, int offset) {
    Component editor = ((CellAdapter) column).getEditor();
    String groupId = (String) fc.getComponentProperty(editor, ComponentFactory.GROUPID_COMPONENT_PROPERTY);
    if (groupId == null) {
        return false;
    }
    // find the columns offsetted to this column in the original columns
    int orgIindex = tableColumnsBeforeDrag.indexOf(column);
    if (orgIindex == -1) {
        // strange, should not happen
        return false;
    }
    if ((offset < 0 && orgIindex + offset < 0) || (offset > 0 && orgIindex + offset >= tableColumnsBeforeDrag.size())) {
        // no more columns in original set
        return false;
    }
    int currIndex = indexOfColumn(column);
    if (currIndex == -1) {
        // strange, should not happen
        return false;
    }
    TableColumn column2 = tableColumnsBeforeDrag.get(orgIindex + offset);
    Component editor2 = ((CellAdapter) column2).getEditor();
    if (!groupId.equals(fc.getComponentProperty(editor2, ComponentFactory.GROUPID_COMPONENT_PROPERTY))) {
        // original column at offset is not part of the same group
        return false;
    }
    int currIndex2 = indexOfColumn(column2);
    if (currIndex2 == -1) {
        // strange, should not happen
        return false;
    }
    // move this one next to the prev
    if (offset < 0) {
        if (currIndex2 > currIndex) {
            if (currIndex2 != currIndex + offset + 1) {
                getColumnModel().moveColumn(currIndex2, currIndex + offset + 1);
            }
        } else {
            if (currIndex2 != currIndex + offset) {
                getColumnModel().moveColumn(currIndex2, currIndex + offset);
            }
        }
    } else {
        if (currIndex2 < currIndex) {
            if (currIndex2 != currIndex + offset - 1) {
                getColumnModel().moveColumn(currIndex2, currIndex + offset - 1);
            }
        } else {
            if (currIndex2 != currIndex + offset) {
                getColumnModel().moveColumn(currIndex2, currIndex + offset);
            }
        }
    }
    // moved
    return true;
}
Also used : CellAdapter(com.servoy.j2db.smart.dataui.CellAdapter) IComponent(com.servoy.j2db.ui.IComponent) Component(java.awt.Component) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) JComponent(javax.swing.JComponent) JTextComponent(javax.swing.text.JTextComponent) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) TableColumn(javax.swing.table.TableColumn) Point(java.awt.Point)

Example 3 with CellAdapter

use of com.servoy.j2db.smart.dataui.CellAdapter in project servoy-client by Servoy.

the class TableView method isCellEditable.

@Override
public boolean isCellEditable(int row, int column) {
    boolean isCellEditable = super.isCellEditable(row, column);
    if (isCellEditable) {
        Object o = getCellEditor(row, column);
        if (o instanceof CellAdapter && ((CellAdapter) o).getEditor() instanceof IScriptableProvider && ((IScriptableProvider) ((CellAdapter) o).getEditor()).getScriptObject() instanceof ISupportOnRenderCallback) {
            Object value = getValueAt(row, column);
            boolean isSelected = isCellSelected(row, column);
            Component c = ((CellAdapter) o).getTableCellEditorComponent(this, value, isSelected, row, column);
            if (c instanceof IScriptableProvider) {
                IScriptable scriptable = ((IScriptableProvider) c).getScriptObject();
                if (scriptable instanceof ISupportOnRenderCallback) {
                    RenderEventExecutor renderEventExecutor = ((ISupportOnRenderCallback) scriptable).getRenderEventExecutor();
                    if (renderEventExecutor != null) {
                        renderEventExecutor.fireOnRender(false);
                        isCellEditable = c.isEnabled();
                    }
                }
            }
        }
    }
    return isCellEditable;
}
Also used : ISupportOnRenderCallback(com.servoy.j2db.ui.ISupportOnRenderCallback) EventObject(java.util.EventObject) CellAdapter(com.servoy.j2db.smart.dataui.CellAdapter) RenderEventExecutor(com.servoy.j2db.ui.RenderEventExecutor) IScriptableProvider(com.servoy.j2db.scripting.IScriptableProvider) IComponent(com.servoy.j2db.ui.IComponent) Component(java.awt.Component) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) JComponent(javax.swing.JComponent) JTextComponent(javax.swing.text.JTextComponent) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) IScriptable(com.servoy.j2db.scripting.IScriptable)

Example 4 with CellAdapter

use of com.servoy.j2db.smart.dataui.CellAdapter in project servoy-client by Servoy.

the class TableView method getDragSource.

public IComponent getDragSource(Point xy) {
    int columnNrAtXY = columnAtPoint(xy);
    int rowNrAtXY = rowAtPoint(xy);
    if (columnNrAtXY > -1 && rowNrAtXY > -1) {
        CellAdapter column = (CellAdapter) getColumnModel().getColumn(columnNrAtXY);
        Component renderer = column.getTableCellRendererComponent(this, null, false, false, rowNrAtXY, columnNrAtXY);
        if (renderer instanceof IComponent && renderer.isEnabled())
            return (IComponent) renderer;
    }
    return this;
}
Also used : IComponent(com.servoy.j2db.ui.IComponent) CellAdapter(com.servoy.j2db.smart.dataui.CellAdapter) IComponent(com.servoy.j2db.ui.IComponent) Component(java.awt.Component) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) JComponent(javax.swing.JComponent) JTextComponent(javax.swing.text.JTextComponent) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent) Point(java.awt.Point)

Example 5 with CellAdapter

use of com.servoy.j2db.smart.dataui.CellAdapter in project servoy-client by Servoy.

the class TableView method setSortStatus.

public boolean setSortStatus(IFoundSetInternal foundset) {
    if (foundset != null) {
        List<SortColumn> sortCols = foundset.getSortColumns();
        if (sortCols != null && sortCols.size() > 0) {
            boolean found = false;
            for (SortColumn sc : sortCols) {
                for (int i = 0; (i < getColumnModel().getColumnCount()); i++) {
                    TableColumn tc = getColumnModel().getColumn(i);
                    if (tc instanceof CellAdapter) {
                        CellAdapter ca = (CellAdapter) tc;
                        if (ca.getDataProviderID() != null) {
                            List<String> sortingProviders = null;
                            Component renderer = ca.getRenderer();
                            if (renderer instanceof ISupportValueList && ((ISupportValueList) renderer).getValueList() != null) {
                                try {
                                    sortingProviders = DBValueList.getShowDataproviders(((ISupportValueList) renderer).getValueList().getValueList(), (Table) foundset.getTable(), ca.getDataProviderID(), application.getFoundSetManager());
                                } catch (RepositoryException ex) {
                                    Debug.error(ex);
                                }
                            }
                            if (sortingProviders == null) {
                                // no related sort, use sort on dataProviderID instead
                                sortingProviders = Collections.singletonList(ca.getDataProviderID());
                            }
                            for (String sortingProvider : sortingProviders) {
                                SortColumn existingSc;
                                try {
                                    FoundSetManager fsm = (FoundSetManager) foundset.getFoundSetManager();
                                    existingSc = fsm.getSortColumn(foundset.getTable(), sortingProvider, false);
                                } catch (Exception e) {
                                    Debug.error(e);
                                    continue;
                                }
                                if (sc.equalsIgnoreSortorder(existingSc)) {
                                    if (!found) {
                                        // clear old sort
                                        updateSortStatus(-1, true);
                                    }
                                    found = true;
                                    updateSortStatus(ca.getModelIndex(), sc.getSortOrder() == SortColumn.ASCENDING);
                                }
                            }
                        }
                    }
                }
            }
            return found;
        }
    }
    return false;
}
Also used : FoundSetManager(com.servoy.j2db.dataprocessing.FoundSetManager) Table(com.servoy.j2db.persistence.Table) FixedJTable(com.servoy.j2db.gui.FixedJTable) ITable(com.servoy.j2db.persistence.ITable) JTable(javax.swing.JTable) ISupportValueList(com.servoy.j2db.ui.ISupportValueList) RepositoryException(com.servoy.j2db.persistence.RepositoryException) SortColumn(com.servoy.j2db.dataprocessing.SortColumn) TableColumn(javax.swing.table.TableColumn) Point(java.awt.Point) RepositoryException(com.servoy.j2db.persistence.RepositoryException) CellAdapter(com.servoy.j2db.smart.dataui.CellAdapter) IComponent(com.servoy.j2db.ui.IComponent) Component(java.awt.Component) GraphicalComponent(com.servoy.j2db.persistence.GraphicalComponent) IFieldComponent(com.servoy.j2db.ui.IFieldComponent) JComponent(javax.swing.JComponent) JTextComponent(javax.swing.text.JTextComponent) IRuntimeComponent(com.servoy.j2db.ui.runtime.IRuntimeComponent)

Aggregations

CellAdapter (com.servoy.j2db.smart.dataui.CellAdapter)7 Component (java.awt.Component)6 JComponent (javax.swing.JComponent)6 GraphicalComponent (com.servoy.j2db.persistence.GraphicalComponent)4 IComponent (com.servoy.j2db.ui.IComponent)4 IFieldComponent (com.servoy.j2db.ui.IFieldComponent)4 IRuntimeComponent (com.servoy.j2db.ui.runtime.IRuntimeComponent)4 JTextComponent (javax.swing.text.JTextComponent)4 Point (java.awt.Point)3 ListView (com.servoy.j2db.smart.ListView)2 TableView (com.servoy.j2db.smart.TableView)2 PortalComponent (com.servoy.j2db.smart.dataui.PortalComponent)2 EventObject (java.util.EventObject)2 TableColumn (javax.swing.table.TableColumn)2 Wrapper (org.mozilla.javascript.Wrapper)2 FoundSetManager (com.servoy.j2db.dataprocessing.FoundSetManager)1 SortColumn (com.servoy.j2db.dataprocessing.SortColumn)1 FixedJTable (com.servoy.j2db.gui.FixedJTable)1 ITable (com.servoy.j2db.persistence.ITable)1 RepositoryException (com.servoy.j2db.persistence.RepositoryException)1