use of com.servoy.j2db.ui.ISupportValueList in project servoy-client by Servoy.
the class ScrollResponseHeaderContainer method initializeComponent.
@SuppressWarnings("nls")
private void initializeComponent(final Component c, AbstractBase view, IPersist element) {
if (dal != null && dal.isDestroyed()) {
Debug.error("Trying to initialize a component: " + c + " of " + view + " element: " + element + " that is in a destroyed tableview", new RuntimeException());
return;
}
if (// Don't know any other place for this
view instanceof Portal && c instanceof IDisplayData) {
String id = ((IDisplayData) c).getDataProviderID();
if (id != null && !ScopesUtils.isVariableScope(id) && id.startsWith(((Portal) view).getRelationName() + '.')) {
((IDisplayData) c).setDataProviderID(id.substring(((Portal) cellview).getRelationName().length() + 1));
}
}
if (!isListViewMode() && c instanceof WebDataCheckBox) {
// $NON-NLS-1$
((WebDataCheckBox) c).setText("");
}
if (element != null) {
// apply to this cell the state of the columnIdentifier IComponent, do keep the location that is set by the tableview when creating these components the first time.
// for listview this is the location to use.
Point loc = ((IComponent) c).getLocation();
int height = ((IComponent) c).getSize().height;
PropertyCopy.copyElementProps((IComponent) elementToColumnIdentifierComponent.get(element), (IComponent) c);
if (!isListViewMode()) {
((IComponent) c).setLocation(loc);
// it shouldn't be possible to change the height
if (c instanceof IScriptableProvider) {
IScriptable so = ((IScriptableProvider) c).getScriptObject();
if (so instanceof IRuntimeComponent) {
IRuntimeComponent ic = (IRuntimeComponent) so;
if (ic.getHeight() != height) {
ic.setSize(ic.getWidth(), height);
}
}
}
}
} else {
// $NON-NLS-1$
Debug.log("Cannot find the IPersist element for cell " + c.getMarkupId());
}
if (c instanceof IDisplayData) {
IDisplayData cdd = (IDisplayData) c;
if (!(dal != null && dal.getFormScope() != null && cdd.getDataProviderID() != null && // skip for form variables
dal.getFormScope().get(cdd.getDataProviderID()) != Scriptable.NOT_FOUND)) {
cdd.setValidationEnabled(validationEnabled);
}
} else if (c instanceof IDisplayRelatedData) {
((IDisplayRelatedData) c).setValidationEnabled(validationEnabled);
} else if (c instanceof IServoyAwareBean) {
((IServoyAwareBean) c).setValidationEnabled(validationEnabled);
}
addClassToCellComponent(c);
if (// the check could be extended against IDelegate<?>
c instanceof WebDataCompositeTextField) {
Object delegate = ((WebDataCompositeTextField) c).getDelegate();
if (delegate instanceof Component) {
// make sure that this class is added accordingly in TemplateGenerator as a style selector containing relevant properties
addClassToCellComponent((Component) delegate);
}
}
if (c instanceof ISupportValueList) {
ISupportValueList idVl = (ISupportValueList) elementToColumnIdentifierComponent.get(element);
IValueList list;
if (idVl != null && (list = idVl.getValueList()) != null) {
ValueList valuelist = application.getFlattenedSolution().getValueList(list.getName());
if (valuelist != null && valuelist.getValueListType() == IValueListConstants.CUSTOM_VALUES) {
((ISupportValueList) c).setValueList(list);
}
}
}
applyClientProperties(c, element);
}
use of com.servoy.j2db.ui.ISupportValueList in project servoy-client by Servoy.
the class ColumnSortListener method mouseClicked.
/*
* (non-Javadoc)
*
* @see java.awt.event.MouseAdapter#mouseClicked(java.awt.event.MouseEvent)
*/
@Override
public void mouseClicked(final MouseEvent e) {
if (!table.isEnabled())
return;
if (e.getButton() == MouseEvent.BUTTON1) {
if (fc != null)
fc.setLastKeyModifiers(e.getModifiers());
TableColumnModel colModel = table.getColumnModel();
if (colModel == null) {
return;
}
int columnModelIndex = colModel.getColumnIndexAtX(e.getX());
if (columnModelIndex < 0) {
return;
}
final TableColumn column = colModel.getColumn(columnModelIndex);
if (column == null) {
return;
}
int modelIndex = column.getModelIndex();
if (modelIndex < 0) {
return;
}
if (table.getModel() instanceof IFoundSetInternal && application.getFoundSetManager().getEditRecordList().stopIfEditing((IFoundSetInternal) table.getModel()) != ISaveConstants.STOPPED) {
return;
}
Integer columnIndex = Integer.valueOf(columnModelIndex);
if (lastColumnIndex.containsKey(columnIndex)) {
lastSortAsc = !lastColumnIndex.get(columnIndex).booleanValue();
} else {
lastSortAsc = true;
if (fc != null && column instanceof CellAdapter && ((CellAdapter) column).getDataProviderID() != null && e.getClickCount() <= 1 && table.getModel() instanceof IFoundSetInternal) {
IFoundSetInternal foundset = (IFoundSetInternal) table.getModel();
List<SortColumn> sortCols = foundset.getSortColumns();
if (sortCols != null && sortCols.size() > 0) {
CellAdapter ca = (CellAdapter) column;
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 ex) {
Debug.error(ex);
continue;
}
for (SortColumn sc : sortCols) {
if (sc.equalsIgnoreSortorder(existingSc)) {
lastSortAsc = sc.getSortOrder() == SortColumn.DESCENDING;
}
}
}
}
}
}
if (!e.isShiftDown()) {
// clear previous data
lastColumnIndex.clear();
}
lastColumnIndex.put(columnIndex, Boolean.valueOf(lastSortAsc));
if (column instanceof CellAdapter && table.getModel() instanceof IFoundSetInternal) {
try {
if (sortTimer != null) {
sortTimer.stop();
}
sortTimer = new Timer(300, new AbstractAction() {
public void actionPerformed(ActionEvent event) {
try {
String dataProviderID = ((CellAdapter) column).getDataProviderID();
int labelForOnActionMethodId = 0;
if (((CellAdapter) column).getHeaderRenderer() instanceof LFAwareSortableHeaderRenderer) {
labelForOnActionMethodId = ((LFAwareSortableHeaderRenderer) ((CellAdapter) column).getHeaderRenderer()).getOnActionMethodID();
}
if (fc != null && labelForOnActionMethodId > 0) {
LFAwareSortableHeaderRenderer renderer = (LFAwareSortableHeaderRenderer) (((CellAdapter) column).getHeaderRenderer());
fc.executeFunction(String.valueOf(labelForOnActionMethodId), Utils.arrayMerge((new Object[] { getJavaScriptEvent(e, JSEvent.EventType.action, renderer.getName()) }), Utils.parseJSExpressions(renderer.getFlattenedMethodArguments("onActionMethodID"))), true, null, false, // $NON-NLS-1$//$NON-NLS-2$
"onActionMethodID");
} else if (fc != null && fc.getForm().getOnSortCmdMethodID() > 0) {
// Also execute the on sort command on none data providers (like a label) then they can do there own sort.
fc.executeFunction(String.valueOf(fc.getForm().getOnSortCmdMethodID()), Utils.arrayMerge((new Object[] { dataProviderID, Boolean.valueOf(lastSortAsc), getJavaScriptEvent(e, JSEvent.EventType.none, null) }), Utils.parseJSExpressions(fc.getForm().getFlattenedMethodArguments("onSortCmdMethodID"))), true, null, false, // $NON-NLS-1$//$NON-NLS-2$
"onSortCmdMethodID");
} else if (dataProviderID != null && fc.getForm().getOnSortCmdMethodID() != -1) {
List<String> sortingProviders = null;
IFoundSetInternal model = (IFoundSetInternal) table.getModel();
Component renderer = ((CellAdapter) column).getRenderer();
if (renderer instanceof ISupportValueList && ((ISupportValueList) renderer).getValueList() != null) {
try {
sortingProviders = DBValueList.getShowDataproviders(((ISupportValueList) renderer).getValueList().getValueList(), (Table) model.getTable(), dataProviderID, application.getFoundSetManager());
} catch (RepositoryException ex) {
Debug.error(ex);
}
}
if (sortingProviders == null) {
// no related sort, use sort on dataProviderID instead
sortingProviders = Collections.singletonList(dataProviderID);
}
try {
List<SortColumn> list = e.isShiftDown() ? model.getSortColumns() : new ArrayList<SortColumn>();
for (String sortingProvider : sortingProviders) {
FoundSetManager fsm = ((FoundSetManager) model.getFoundSetManager());
SortColumn sc = fsm.getSortColumn(model.getTable(), sortingProvider, false);
if (sc != null && sc.getColumn().getDataProviderType() != IColumnTypes.MEDIA) {
for (SortColumn oldColumn : list) {
if (oldColumn.equalsIgnoreSortorder(sc)) {
sc = oldColumn;
break;
}
}
if (!list.contains(sc))
list.add(sc);
sc.setSortOrder(lastSortAsc ? SortColumn.ASCENDING : SortColumn.DESCENDING);
}
model.sort(list, false);
}
} catch (Exception ex) {
Debug.error(ex);
}
}
} finally {
sortTimer.stop();
}
}
});
sortTimer.start();
} catch (Exception ex) {
Debug.error(ex);
}
}
}
}
use of com.servoy.j2db.ui.ISupportValueList in project servoy-client by Servoy.
the class AbstractRuntimeValuelistComponent method setValueListItems.
public void setValueListItems(Object value) {
if (getComponent() instanceof ISupportValueList) {
IValueList list = ((ISupportValueList) getComponent()).getValueList();
if (list != null && (value instanceof JSDataSet || value instanceof IDataSet)) {
String name = list.getName();
ValueList valuelist = application.getFlattenedSolution().getValueList(name);
if (valuelist != null && valuelist.getValueListType() == ValueList.CUSTOM_VALUES) {
ParsedFormat format = null;
int type = 0;
if (list instanceof CustomValueList) {
format = ((CustomValueList) list).getFormat();
type = ((CustomValueList) list).getValueType();
}
IValueList newVl = ValueListFactory.fillRealValueList(application, valuelist, ValueList.CUSTOM_VALUES, format, type, value);
((ISupportValueList) getComponent()).setValueList(newVl);
}
}
}
}
use of com.servoy.j2db.ui.ISupportValueList 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;
}
use of com.servoy.j2db.ui.ISupportValueList in project servoy-client by Servoy.
the class ScrollResponseHeaderContainer method tableChanged.
/**
* @see javax.swing.event.TableModelListener#tableChanged(javax.swing.event.TableModelEvent)
*/
public void tableChanged(TableModelEvent e) {
// as changed, as it will be faster on the client the component replace
if ((e.getType() == TableModelEvent.UPDATE) && (e.getFirstRow() == e.getLastRow()) && (nrUpdatedListItems < 20)) {
Component component = table.get(Integer.toString(e.getFirstRow()));
if (component instanceof ListItem) {
((ListItem) component).visitChildren(IProviderStylePropertyChanges.class, new IVisitor<Component>() {
public Object component(Component comp) {
if ((comp instanceof IDisplayData) || !(comp instanceof ILabel)) {
if (comp instanceof ISupportsNeedEntireState && ((ISupportsNeedEntireState) comp).needEntireState()) {
// it if has tags - mark as changed; it could be enhanced further by also know what was last-rendered on tags, not just simple dataproviders
((IProviderStylePropertyChanges) comp).getStylePropertyChanges().setChanged();
} else {
// try to mark cells as changed only if there was a real value change; otherwise there is no use to replace the whole row...
checkForValueChanges(comp);
}
}
// else labels/buttons that don't display data are not changed
return CONTINUE_TRAVERSAL_BUT_DONT_GO_DEEPER;
}
});
nrUpdatedListItems++;
IModel<IRecordInternal> newModel = table.getListItemModel(table.getModel(), e.getFirstRow());
IModel oldModel = ((ListItem) component).getModel();
if (newModel != null && oldModel != null && newModel.getObject() != null && !newModel.getObject().equals(oldModel.getObject())) {
// refresh model if it changed
((ListItem) component).setModel(newModel);
}
}
} else {
if (!isRendering && (!isScrollMode() || !(scrollBehavior != null && scrollBehavior.isGettingRows()))) {
if (isScrollMode())
resetScrollParams();
getStylePropertyChanges().setValueChanged();
}
}
// This is just an heuristic for filtering out the sort event from all table changed events that are raised.
if (currentData != null && e.getColumn() == TableModelEvent.ALL_COLUMNS && e.getFirstRow() == 0 && elementToColumnHeader.size() > 0) {
List<SortColumn> sortCols = currentData.getSortColumns();
if (sortCols != null && sortCols.size() > 0) {
Map<String, Boolean> sortMap = new HashMap<String, Boolean>();
for (IPersist persist : elementToColumnHeader.keySet()) {
SortableCellViewHeader sortableCellViewHeader = (SortableCellViewHeader) elementToColumnHeader.get(persist);
sortableCellViewHeader.setResizeImage(R_ARROW_OFF);
}
for (SortColumn sc : sortCols) {
for (IPersist persist : elementToColumnHeader.keySet()) {
Component comp = elementToColumnIdentifierComponent.get(persist);
SortableCellViewHeader sortableCellViewHeader = (SortableCellViewHeader) elementToColumnHeader.get(persist);
if (comp instanceof IDisplayData && ((IDisplayData) comp).getDataProviderID() != null) {
IDisplayData dispComp = (IDisplayData) comp;
List<String> sortingProviders = null;
if (dispComp instanceof ISupportValueList && ((ISupportValueList) dispComp).getValueList() != null) {
try {
sortingProviders = DBValueList.getShowDataproviders(((ISupportValueList) dispComp).getValueList().getValueList(), (Table) currentData.getTable(), dispComp.getDataProviderID(), currentData.getFoundSetManager());
} catch (RepositoryException ex) {
Debug.error(ex);
}
}
if (sortingProviders == null) {
// no related sort, use sort on dataProviderID instead
sortingProviders = Collections.singletonList(dispComp.getDataProviderID());
}
for (String sortingProvider : sortingProviders) {
SortColumn existingSc;
try {
FoundSetManager fsm = (FoundSetManager) currentData.getFoundSetManager();
existingSc = fsm.getSortColumn(currentData.getTable(), sortingProvider, false);
} catch (RepositoryException ex) {
Debug.error(ex);
continue;
}
if (sc.equalsIgnoreSortorder(existingSc)) {
boolean descending = sc.getSortOrder() == SortColumn.DESCENDING;
sortableCellViewHeader.setResizeImage(descending ? R_ARROW_UP : R_ARROW_DOWN);
sortMap.put(sortableCellViewHeader.getId(), Boolean.valueOf(!descending));
}
}
}
}
}
headers.recordSort(sortMap);
}
}
MainPage mp = table.findParent(MainPage.class);
if (mp != null)
mp.triggerBrowserRequestIfNeeded();
}
Aggregations