📄 qformviewimpl.java
字号:
//draw field if it exists
control = linkControlFromModel(col.getFieldID()).getBaseView();
} else if(findButtonMeta(col.getFieldID()) != null) {//skip buttons
continue;
} else if(hasChartModel(col.getFieldID())) {
control = createChart(col.getFieldID());
} else if (htmlElements.containsKey(col.getFieldID())) {
control = new QFormHtmlElement((String)htmlElements.get(col.getFieldID()));
} else if (isASystemButton(col.getFieldID())) {
control = new QErrorLabel(getFormLabelsOrientation(), "");
} else {
control = new QErrorLabel(getFormLabelsOrientation(), "!!!UNKNOWN_ELEMENT <" + col.getFieldID() + ">!!!");
}
}
if(getLayoutMeta().isControlHidden(col.getFieldID())) {
//if control is hidden - add space into grid
control = new QErrorLabel(getFormLabelsOrientation(), "");
createdHiddenControls.add(col.getFieldID());
}
addWidget(colIdx, rowIdx, col.getColspan(), col.getRowspan(), control);
}
}
//and now creating all residuary hidden controls
String[] hiddenControls = getLayoutMeta().getHiddenControls();
for(int i = 0; i < hiddenControls.length; i++) {
String hiddenControl = hiddenControls[i];
if(!createdHiddenControls.contains(hiddenControl)) {
linkControlFromModel(hiddenControl);
}
}
}
private void fillFormFromModel() {
//add controls
ArrayList ids = model.elementsKeys();
for(int i = 0, n = ids.size(); i < n; i++) {
String key = (String) ids.get(i);
QFormElement control = linkControlFromModel(key);
if(control.getBaseModel().isLinkable() && control.getBaseModel().getBaseMeta().getLinkedForm() != null) {
control.getBaseView().addLinkedFormStyle();
}
putControl(control, null);
}
}
private FormButtonMeta findButtonMeta(String buttonId) {
int index = buttonsMeta.indexOf(new FormButtonMeta(buttonId, ""));
if(index == -1) {
return null;
} else {
return (FormButtonMeta) buttonsMeta.get(index);
}
}
private boolean hasChartModel(String chartId) {
return getChartModel(chartId) != null;
}
private ChartModel getChartModel(String chartId) {
for (Iterator it = chartModels.iterator(); it.hasNext();) {
ChartModel model = (ChartModel) it.next();
ChartMeta meta = model.getMeta();
if(meta != null && chartId.equalsIgnoreCase(meta.getID().toString()))
return model;
}
return null;
}
private QFormLayoutElement createChart(String chartId){
ChartModel chartModel = getChartModel(chartId);
if(chartModel == null)
return null;
QChart chart = new QChart(chartModel);
chart.getController().getEventSource().addEventListener(el);
return (QFormLayoutElement) chart.getView().getWidget();
}
private QFormElement linkControlFromModel(String key) {
FieldMeta elementMeta = model.getElementMeta(key);
QFormElement control = QFormComponentsFactory.createWidetForElement(
elementMeta, this, getFormLabelsOrientation());
controls.put(key, control);//need for fast searching
control.getBaseController().getEventSource().addEventListener(el);
return control;
}
EventListener el = new EventListener() {
public void onEvent(Event event, Widget sender) {
if (event == QFormElementView.Events.TEXTAREA_FOCUSED) {
textAreaHasFocus = true;
} else if (event == QFormElementView.Events.TEXTAREA_FOCUS_LOST) {
textAreaHasFocus = false;
} else {
formElementsEventSource.fireEvent(event);
}
}
};
public QFormElement getControl(Object key) {
return (QFormElement) controls.get(key);
}
private void putControl(QFormElement control, QFormPlaceConstraint elementConstraint) {
// System.out.println("X:" + lastXPosition + ", Y:" + lastYPosition);
addWidget(lastXPosition, lastYPosition, 1, 1, control.getBaseView());
switch(formLayout) {
case QFormLayout.HORIZONTAL_FLOW_LAYOUT: {
lastXPosition++;
if(lastXPosition >= gridWidth) {
lastXPosition = 0;
lastYPosition++;
}
if(lastYPosition >= gridHeight) {
lastYPosition = 0;
}
break;
}
case QFormLayout.VERTICAL_FLOW_LAYOUT: {
lastYPosition++;
if(lastYPosition >= gridHeight) {
lastYPosition = 0;
lastXPosition++;
}
if(lastXPosition >= gridWidth) {
lastXPosition = 0;
}
break;
}
case QFormLayout.XY_LAYOUT: {
if(elementConstraint != null) {
if(elementConstraint.getConstraintForLayoutType() == QFormLayout.XY_LAYOUT) {
lastXPosition = ((XYConstraint) elementConstraint).getX();
lastYPosition = ((XYConstraint) elementConstraint).getY();
}
}
break;
}
default: {//simply place elements by diagonal
lastYPosition++;
lastYPosition++;
break;
}
}
}
public void dataChanged() {
setCaption(model.getFormTitle());
ArrayList keys = model.elementsKeys();
for(int i = 0; i < keys.size(); i++) {
String key = (String) keys.get(i);
dataChanged(key);
}
}
public void dataChanged(String elementId) {
if(controls.containsKey(elementId)) {
QFormElement control = getElement(elementId);
FieldData fieldData = model.getElementData(elementId);
if(fieldData != null) {
control.getBaseModel().setBaseData(fieldData);
}
}
}
public void dataOnDemandCome(FieldOnDemandData data) {
if(data != null) {
QFormElement qFormElement = getControl(data.getFieldID());
if(qFormElement != null) {
qFormElement.getBaseModel().setFieldOnDemandData(data);
}
}
}
public void setDataRequirementsListener(DataRequirementsListener listener) {
dataRequirementsListener = listener;
}
public void needMoreData(FieldDataRequest request) {
if(dataRequirementsListener != null) {
dataRequirementsListener.needMoreData(request);
}
}
public void disableCommonChangeButton() {
setCommonActionEnabled(QFormController.Events.FORM_CHANGE_BUTTON_EVENT, false);
}
public void allowModificationsForSearch() {
setEnabledForSearch();
}
public void allowModificationsForEdit() {
setEnabledForEdit();
}
public void allowModificationsForReportDesign() {
setEnabledForReportDesign();
}
public void denyModifications() {
disable();
}
public void disableCommonSearchButton() {
setCommonActionEnabled(QFormController.Events.FORM_SEARCH_BUTTON_EVENT, false);
}
public void disableCommonClearButton() {
setCommonActionEnabled(QFormController.Events.FORM_CLEAR_BUTTON_EVENT, false);
}
public void disableCommonNewButton() {
setCommonActionEnabled(QFormController.Events.FORM_NEW_BUTTON_EVENT, false);
}
public void enableAllCommonButtons() {
setCommonActionEnabled(QForm.DEFAULT_BUTTON_EVENTS, true);
}
public void populateForm() {
dataChanged();
}
public void showChangeButton() {
if(changeOrUpdateButton != null) {
commonActionPanel.removeButton(changeOrUpdateButton);
commonActionPanel.addButton(QFormController.Events.FORM_CHANGE_BUTTON_EVENT, changeOrUpdateButton);
changeOrUpdateButton.setCaption(getUnderlined(CHANGE_BUTTON_CAPTION));
changeOrUpdateButton.setTooltip(getKeyCodeCaption(CHANGE_BUTTON_CAPTION));
presentButtons.remove(UPDATE_BUTTON_CAPTION);
presentButtons.add(CHANGE_BUTTON_CAPTION);
}
}
public void showUpdateButton() {
if(changeOrUpdateButton != null) {
commonActionPanel.removeButton(changeOrUpdateButton);
commonActionPanel.addButton(QFormController.Events.FORM_UPDATE_BUTTON_EVENT, changeOrUpdateButton);
changeOrUpdateButton.setCaption(getUnderlined(UPDATE_BUTTON_CAPTION));
changeOrUpdateButton.setTooltip(getKeyCodeCaption(UPDATE_BUTTON_CAPTION));
presentButtons.remove(CHANGE_BUTTON_CAPTION);
presentButtons.add(UPDATE_BUTTON_CAPTION);
}
}
private boolean shallColspannedControlUseHeaders(QFormLayoutElement control, int colIdx, int[] colsWidth) {
int result = 0;
for (int i = colIdx; i < (colIdx + control.getColSpan()) && i < colsWidth.length; i++) {
result += colsWidth[i];
}
return result == 0 && getLayoutMeta().containHeaders() && control.getClientWidth() > 0;
}
private Set enlargeSpannedControlsUseHeaders(List[] rows, int[] colsWidth) {
Set controlsForEnlarging = new HashSet();
//enlarge all spanned controls
//enlarge controls which are placed in columns without any single input controls
for (int rowIdx = 0; rowIdx < rows.length; rowIdx++) {
List row = rows[rowIdx];
for (int colIdx = 0; colIdx < row.size(); colIdx++) {
QFormLayoutElement control = (QFormLayoutElement) row.get(colIdx);
if (control != null && control.getColSpan() > 1) {
//let's check - if this control is placed in columns with no-client-width
//elements - set its size according headers, otherwise - use default span
if (shallColspannedControlUseHeaders(control, colIdx, colsWidth)) {
int clientWidth = 0;
for (int i = colIdx; i < colIdx + control.getColSpan(); i++) {
FormLayoutMeta.ColumnHeader header = getLayoutMeta().getHeader(i);
if (header != null) {
clientWidth += header.getClientWidth();
}
}
if (clientWidth > 0) {
control.setClientWidth(clientWidth);
control.setWidth(StringUtil.pixelToSize(clientWidth + control.getFilledWidth()));
}
} else {
controlsForEnlarging.add(control);
}
}
}
}
return controlsForEnlarging;
}
/**
* Traverses all spanned controls which are placed in columns with client-side controls
* and sets their width to required size.
* Attention: if colspanned control is placed in columns with no-client-resizing
* controls (e.g. buttons, checkboxes etc) - it shall be resized according headers.
* @param controlsForEnlarging set of {@link com.queplix.core.client.controls.QFormLayoutElement}
*/
private void enlargeTheRestOfSpannedControls(Set controlsForEnlarging) {
//enlarge the rest of spanned controls
for (Iterator it = controlsForEnlarging.iterator(); it.hasNext();) {
QFormLayoutElement control = (QFormLayoutElement) it.next();
if (control.allowColspanning()) {
control.setWidth("100%");
control.setClientWidth(control.getOffsetWidth() - control.getFilledWidth() - 1);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -