use of com.servoy.j2db.util.IStyleRule in project servoy-client by Servoy.
the class SwingForm method initView.
public IView initView(IApplication application, FormController fp, int viewType) {
view = null;
IDataRenderer[] dataRenderers = fp.getDataRenderers();
setTitleHeader((JComponent) dataRenderers[Part.TITLE_HEADER]);
setHeader((JComponent) dataRenderers[Part.HEADER]);
setLeadingGrandSummary((JComponent) dataRenderers[Part.LEADING_GRAND_SUMMARY]);
setTrailingGrandSummary((JComponent) dataRenderers[Part.TRAILING_GRAND_SUMMARY]);
setFooter((JComponent) dataRenderers[Part.FOOTER]);
// remove any left slider
setWest(null);
switch(viewType) {
case FormController.LOCKED_LIST_VIEW:
case IForm.LIST_VIEW:
view = new ListView();
PrototypeState proto = null;
if (fp.getFoundSet() != null) {
proto = fp.getFoundSet().getPrototypeState();
} else {
proto = new PrototypeState(null);
}
// this call is extreemly inportant, it prevent all rows retrieval
((ListView) view).setPrototypeCellValue(proto);
FormBodyEditor editor = null;
if (dataRenderers[FormController.FORM_RENDERER] != null) {
Component[] rendererComponents = ((Container) dataRenderers[FormController.FORM_RENDERER]).getComponents();
for (Component rendererComponent : rendererComponents) {
if (rendererComponent instanceof ISupportAsyncLoading) {
// in listview it is impossible to get lazy loaded images displaying correctly, due to needed repaintfire, which we cannot initiate
((ISupportAsyncLoading) rendererComponent).setAsyncLoadingEnabled(false);
}
rendererComponent.setFocusable(false);
}
((Component) dataRenderers[FormController.FORM_RENDERER]).setFocusable(false);
}
editor = new FormBodyEditor((DataRenderer) dataRenderers[FormController.FORM_EDITOR]);
if (dataRenderers[FormController.FORM_RENDERER] != null) {
DataRenderer dr = (DataRenderer) dataRenderers[FormController.FORM_RENDERER];
dr.setRenderer(true);
String bgcolorCalc = fp.getForm().getRowBGColorCalculation();
if (bgcolorCalc != null) {
// dr.setRowBGColorProvider(bgcolorCalc);
dr.setShowSelection(false);
// $NON-NLS-1$
((ListView) view).setRowBGColorScript(bgcolorCalc, fp.getForm().getFlattenedMethodArguments("rowBGColorCalculation"));
((DataRenderer) dataRenderers[FormController.FORM_EDITOR]).setShowSelection(false);
}
((ListView) view).setCellRenderer(dr);
} else {
// form with no body part - used only for printing probably
((ListView) view).setCellRenderer(new ListCellRenderer() {
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
// $NON-NLS-1$
return new JLabel("");
}
});
}
((ListView) view).setCellEditor(editor);
((ListView) view).setRendererSameAsEditor(false);
((ListView) view).setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
break;
case FormController.LOCKED_TABLE_VIEW:
case FormController.TABLE_VIEW:
view = new TableView(application, fp, fp.getForm(), fp.getForm(), fp.getScriptExecuter(), dataRenderers[Part.HEADER], dataRenderers[Part.LEADING_GRAND_SUMMARY], false);
if (dataRenderers[FormController.FORM_EDITOR] != null)
dataRenderers[FormController.FORM_EDITOR].destroy();
dataRenderers[FormController.FORM_EDITOR] = (IDataRenderer) view;
if (formController.getBodyStyle() != null) {
Pair<IStyleSheet, IStyleRule> pairStyle = ComponentFactory.getCSSPairStyleForForm(application, fp.getForm());
if (pairStyle != null && pairStyle.getLeft() != null) {
Border border = pairStyle.getLeft().getBorder(formController.getBodyStyle());
if (border != null) {
innerPanel.setBorder(border);
}
}
}
break;
case IForm.LOCKED_RECORD_VIEW:
case IForm.RECORD_VIEW:
default:
view = new RecordView(formController);
if (dataRenderers[FormController.FORM_EDITOR] != null) {
((DataRenderer) dataRenderers[FormController.FORM_EDITOR]).setShowSelection(false);
((RecordView) view).setCellRenderer((DataRenderer) dataRenderers[FormController.FORM_EDITOR]);
}
int form_id = fp.getForm().getNavigatorID();
if (form_id == 0) {
StyledEnablePanel slider = ((RecordView) view).getSliderComponent();
if (bgColor != null)
slider.setBackground(bgColor);
setWest(slider);
}
}
getVerticalScrollBar().setValue(1);
getVerticalScrollBar().setValue(0);
setViewportView((JComponent) view);
if (view instanceof TableView) {
// the table view needs it's orientation set correctly
OrientationApplier.setOrientationToAWTComponent(this, application.getLocale(), application.getSolution().getTextOrientation());
}
if (view instanceof ListView) {
view.requestFocus();
}
OrientationApplier.setOrientationToAWTComponent(this, application.getLocale(), application.getSolution().getTextOrientation());
if ((bgColor != null) && (view instanceof ListView))
((ListView) view).setBackground(bgColor);
// except if it's a table view, that is always transparent
if (!(view instanceof TableView)) {
setOpaque(isOpaque());
} else {
for (int i = FormController.FORM_RENDERER + 1; i < dataRenderers.length; i++) {
if (dataRenderers[i] != null && !(dataRenderers[i] instanceof TableView)) {
dataRenderers[i].setOpaque(isOpaque());
}
}
}
return view;
}
use of com.servoy.j2db.util.IStyleRule in project servoy-client by Servoy.
the class DataRenderer method getListCellRendererComponent.
public Component getListCellRendererComponent(JComponent rendererParentCanBeNull, Object value, int index, boolean isSelected, boolean cellHasFocus) {
this.selected = isSelected;
// if (isSelected)
// {
// setBorder(focusBorder);
// }
// else
// {
// setBorder(noFocusBorder);
// }
boolean bgRowColorSet = false;
// if in Renderer mode for a the List then a renderer can't stop editing.
if (value instanceof IRecordInternal) {
IRecordInternal val = (IRecordInternal) value;
// if in list view, we need to set the render state for each list item here
if (rendererParentCanBeNull != null) {
DataAdapterList.setDataRendererComponentsRenderState(this, val);
}
dataAdapterList.setRecord(val, !isRenderer);
// setOpaque(true);
if (index != -1) {
boolean specialStateCase = (val instanceof PrototypeState || val instanceof FindState || val.getRawData() == null);
if (strRowBGColorProvider == null && !specialStateCase) {
if (rendererParentCanBeNull instanceof ISupportRowBGColorScript) {
strRowBGColorProvider = ((ISupportRowBGColorScript) rendererParentCanBeNull).getRowBGColorScript();
rowBGColorArgs = ((ISupportRowBGColorScript) rendererParentCanBeNull).getRowBGColorArgs();
}
// $NON-NLS-1$
if (strRowBGColorProvider == null)
strRowBGColorProvider = "servoy_row_bgcolor";
isRowBGColorCalculation = val.getRawData().containsCalculation(strRowBGColorProvider);
if (!isRowBGColorCalculation && strRowBGColorProvider.equals("servoy_row_bgcolor")) {
// $NON-NLS-1$
strRowBGColorProvider = "";
}
defaultColor = getBackground();
}
if (// $NON-NLS-1$
strRowBGColorProvider != null && !"".equals(strRowBGColorProvider)) {
IFoundSetInternal parent = val.getParentFoundSet();
if (parent != null && !specialStateCase) {
Object bg_color = null;
if (isRowBGColorCalculation) {
bg_color = parent.getCalculationValue(val, strRowBGColorProvider, Utils.arrayMerge((new Object[] { new Integer(index), new Boolean(isSelected), null, null, Boolean.FALSE }), Utils.parseJSExpressions(rowBGColorArgs)), null);
} else {
try {
FormController currentForm = dataAdapterList.getFormController();
bg_color = currentForm.executeFunction(strRowBGColorProvider, Utils.arrayMerge((new Object[] { new Integer(index), new Boolean(isSelected), null, null, currentForm.getName(), val, Boolean.FALSE }), Utils.parseJSExpressions(rowBGColorArgs)), false, null, true, null);
} catch (Exception ex) {
Debug.error(ex);
}
}
if (bg_color != null && !(bg_color.toString().trim().length() == 0) && !(bg_color instanceof Undefined)) {
bgRowColorSet = true;
setBackground(PersistHelper.createColor(bg_color.toString()));
} else {
setBackground(defaultColor);
}
} else {
setBackground(defaultColor);
}
}
if (rendererParentCanBeNull instanceof ISupportRowStyling && !specialStateCase && !bgRowColorSet) {
ISupportRowStyling oddEvenStyling = (ISupportRowStyling) rendererParentCanBeNull;
IStyleSheet ss = oddEvenStyling.getRowStyleSheet();
IStyleRule style = isSelected ? oddEvenStyling.getRowSelectedStyle() : null;
if (style != null && style.getAttributeCount() == 0)
style = null;
if (style == null) {
// because index = 0 means record = 1
style = (index % 2 == 0) ? oddEvenStyling.getRowOddStyle() : oddEvenStyling.getRowEvenStyle();
}
if (ss != null && style != null) {
Color bgColor = ss.getBackground(style);
if (bgColor != null) {
showSelection = false;
bgRowColorSet = true;
setBackground(bgColor);
}
}
}
}
}
if (rendererParentCanBeNull != null) {
if (rendererParentCanBeNull.isEnabled() != isEnabled()) {
// Debug.trace(donotusecanbenullifinrecondview.getName()+" "+donotusecanbenullifinrecondview.isEnabled());
// needed for portals
setEnabled(rendererParentCanBeNull.isEnabled());
}
if (bgRowColorSet && !isOpaque()) {
setOpaque(true);
}
dataRendererOnRenderWrapper.getRenderEventExecutor().fireOnRender(hasFocus());
}
return this;
}
use of com.servoy.j2db.util.IStyleRule in project servoy-client by Servoy.
the class DataRendererFactory method completeRenderers.
/**
* Fills all the panels provided in emptyDataRenderers with the components from the form
*
* @param form the form to work with
* @param emptyDataRenderers the orderedHashmap with the Part -> DataRenderer
* @param insets for any border
* @param with of all parts
* @return usesSliding
*/
public Map completeRenderers(IApplication app, Form form, IScriptExecuter listner, Map emptyDataRenderers, int width, boolean printing, ControllerUndoManager undoManager, TabSequenceHelper<Component> tabSequence) throws Exception {
int partHeight = 0;
boolean formHasBgImage = false;
Pair<IStyleSheet, IStyleRule> formStyle = ComponentFactory.getCSSPairStyleForForm(app, form);
if (formStyle != null && formStyle.getRight() != null && formStyle.getRight().hasAttribute(CSS.Attribute.BACKGROUND_IMAGE.toString())) {
formHasBgImage = true;
}
Iterator e2 = form.getParts();
while (e2.hasNext()) {
Part part = (Part) e2.next();
Color bg = ComponentFactory.getPartBackground(app, part, form);
if (bg == null && printing)
bg = Color.white;
DataRenderer panel = (DataRenderer) emptyDataRenderers.get(part);
if (panel != null) {
panel.setDoubleBuffered(!printing);
int total = Math.abs(part.getHeight() - partHeight);
setBasicSettings(panel, bg, new Dimension(width, total), new Point(0, partHeight), printing);
}
partHeight = part.getHeight();
// revert css3 features
Pair<IStyleSheet, IStyleRule> pair = ComponentFactory.getStyleForBasicComponent(app, part, form);
if (panel != null) {
// panel.setBgColor(part.getBackground());
if (pair != null && pair.getRight() != null && pair.getLeft() != null) {
// panel.setCssRule(pair.getRight());
Border border = pair.getLeft().getBorder(pair.getRight());
if (border != null) {
panel.setBorder(border);
}
}
// boolean partHasBgColor = (part.getBackground() != null) ||
// (pair != null && pair.getRight() != null && pair.getRight().hasAttribute(CSS.Attribute.BACKGROUND_COLOR.toString()));
// if (!form.getTransparent() && (formHasBgImage || (partHasBgColor && bg.getAlpha() < 255)))
// {
// panel.setPaintBackgroundOnTopOfFormImage(true);
// }
}
}
// place all the elements
Iterator<IFormElement> e1 = form.getFormElementsSortedByFormIndex();
return placeElements(e1, app, form, listner, emptyDataRenderers, width, 0, 0, printing, false, undoManager, false, tabSequence);
}
use of com.servoy.j2db.util.IStyleRule in project servoy-client by Servoy.
the class CellAdapter method getStyleAttributeForRow.
private Object getStyleAttributeForRow(JTable jtable, boolean isSelected, int row, ISupportRowStyling.ATTRIBUTE rowStyleAttribute) {
Object rowStyleAttrValue = null;
IRecordInternal state = ((IFoundSetInternal) jtable.getModel()).getRecord(row);
boolean specialStateCase = (state instanceof PrototypeState || state instanceof FindState);
if (/* !(renderer instanceof JButton) && */
!specialStateCase) {
if (jtable instanceof ISupportRowStyling) {
ISupportRowStyling oddEvenStyling = (ISupportRowStyling) jtable;
IStyleSheet ss = oddEvenStyling.getRowStyleSheet();
IStyleRule style = isSelected ? oddEvenStyling.getRowSelectedStyle() : null;
if (style != null && style.getAttributeCount() == 0)
style = null;
if (style == null) {
// because index = 0 means record = 1
style = (row % 2 == 0) ? oddEvenStyling.getRowOddStyle() : oddEvenStyling.getRowEvenStyle();
}
rowStyleAttrValue = getStyleAttribute(ss, style, rowStyleAttribute);
}
}
return rowStyleAttrValue;
}
use of com.servoy.j2db.util.IStyleRule in project servoy-client by Servoy.
the class ScrollResponseHeaderContainer method getStyleAttributeForListItem.
private String getStyleAttributeForListItem(ListItem<IRecordInternal> listItem, boolean isSelected, ISupportRowStyling.ATTRIBUTE rowStyleAttribute, boolean asInlineCSSString) {
String listItemAttrValue = null;
final IRecordInternal rec = listItem.getModelObject();
if (rec != null && rec.getRawData() != null) {
IStyleRule style = isSelected ? getRowSelectedStyle() : null;
if (style != null && style.getAttributeCount() == 0)
style = null;
if (style == null) {
// because index = 0 means record = 1
style = (listItem.getIndex() % 2 == 0) ? getRowOddStyle() : getRowEvenStyle();
}
if (asInlineCSSString) {
listItemAttrValue = getStyleAttributeString(style, rowStyleAttribute);
} else {
listItemAttrValue = getStyleAttributeValue(style, rowStyleAttribute);
}
}
return listItemAttrValue;
}
Aggregations