📄 qformviewimpl.java
字号:
}
}
}
/**
* Creates and fills the matrix which contain real positions of all controls
* in the form. Positions are calculated according colspans.
* @return matrix of real control positions.
*/
private List[] calculateRealControlMatrix() {
//create matrix of controls real position (using colspans)
List[] rows = new ArrayList[elementsGrid.getRowCount()];
for(int i = 0; i < rows.length; i++) {
rows[i] = new ArrayList();
}
//fill matrix using colspans
for(int i = 0, n = elementsGrid.getRowCount(); i < n; i++) {
QFormLayoutElement prevElement = null;
for(int j = 0, m = elementsGrid.getCellCount(i); j < m; j++) {
QFormLayoutElement c = (QFormLayoutElement) elementsGrid.getWidget(i, j);
if (j > 0 && prevElement != null) {
QElementsCoupler.getInstance().coupleElements(prevElement, c);
}
prevElement = c;
rows[i].add(c);
//if element has a colspan - add nulls into matrix row
if(c.getColSpan() > 1) {
int colspan = c.getColSpan();
while(colspan-- > 1) {
rows[i].add(null);
}
}
}
}
//and correct matrix using rowspans
for(int i = 0; i < rows.length; i++) {
List row = rows[i];
int colIdx = 0;
for(Iterator it = row.iterator(); it.hasNext();) {
QFormLayoutElement control = (QFormLayoutElement) it.next();
if(control != null && control.getRowSpan() > 1) {
for(int rowIdx = i + 1; rowIdx < rows.length && rowIdx < i + control.getRowSpan(); rowIdx++) {
List bottomRow = rows[rowIdx];
if(colIdx < bottomRow.size()) {
int colspanCounter = control.getColSpan();
while(colspanCounter-- > 0) {
bottomRow.add(colIdx, null);
}
}
}
}
colIdx++;
}
}
return rows;
}
/**
* Calculates max caption with for each column and sets this max width for
* all captions in processed column.
*
* @param rows array of a controls description.
* It looks like:<br/>
* <table border="1">
* <tr>
* <td>[controlA]</td>
* <td>[null]</td>
* <td>[controlB]</td>
* </tr>
* <tr>
* <td>[controlC]</td>
* <td>[controlD]</td>
* <td>[null]</td>
* <td>[controlE]</td>
* </tr>
* </table>
*/
private void setCaptionWidthForAllControls(final List[] rows) {
int width = getFormWidth(rows);
//calculate and set labels width
for(int colIdx = 0; colIdx < width; colIdx++) {
//getting maximum caption width in the current column
int maxCaptionWidth = 0;
for(int rowIdx = 0; rowIdx < rows.length; rowIdx++) {
if(rows[rowIdx].size() > colIdx) {
QFormLayoutElement element = (QFormLayoutElement) rows[rowIdx].get(colIdx);
if(element != null && element.alignableAsHorizontal() &&
element.getCaptionOffsetWidth() > maxCaptionWidth) {
maxCaptionWidth = element.getCaptionOffsetWidth();
}
}
}
//and assign it to all captions
for(int rowIdx = 0; rowIdx < rows.length; rowIdx++) {
if(rows[rowIdx].size() > colIdx) {
QFormLayoutElement element = (QFormLayoutElement) rows[rowIdx].get(colIdx);
if(element != null && element.alignableAsHorizontal()) {
element.setCaptionOffsetWidth(maxCaptionWidth);
}
}
}
}
}
/**
* Returns width of the form. Actually it is a size of the widgest row in
* the form layout.
* @param rows Matrix of controls built according colspans/rowspans.
* @return form width.
*/
private int getFormWidth(final List[] rows) {
//calculate max cols count
int width = 0;
for(int i = 0; i < rows.length; i++) {
if(width < rows[i].size()) {
width = rows[i].size();
}
}
return width;
}
/**
* Sets client widths for all controls accroding headers.
* @param rows array of a controls description.
* @return width of the columns excepting colspanned elements.
*/
private int[] setClientWidth(List[] rows) {
int[] colsWidth = new int[getFormWidth(rows)];
if(getLayoutMeta() != null && getLayoutMeta().containHeaders()) {
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() < 2) {
FormLayoutMeta.ColumnHeader header = getLayoutMeta().getHeader(colIdx);
if(header != null) {
int clientWidth = header.getClientWidth();
if(clientWidth != FormLayoutMeta.CLIENT_WIDTH_NOT_SPECIFIED) {
control.setClientWidth(clientWidth);
}
}
if (control.getClientWidth() > colsWidth[colIdx]) {
colsWidth[colIdx] = control.getClientWidth();
}
}
}
}
}
return colsWidth;
}
private void activateLinks(){
if (links == null) return;
for (int i = 0; i < links.length; i++) {
FormLinkMeta link = links[i];
QFormElement element = getControl(link.getFieldId());
if (element != null) {
element.getBaseView().addLinkedFormStyle();
}
}
}
public void onAttach() {
super.onAttach();
if (!isAlreadyLoaded) {
List[] rows = calculateRealControlMatrix();
int[] colsWidth = setClientWidth(rows);
Set controlsForEnlarging = enlargeSpannedControlsUseHeaders(rows, colsWidth);
setCaptionWidthForAllControls(rows);
enlargeTheRestOfSpannedControls(controlsForEnlarging);
isAlreadyLoaded = true;
}
if (Application.isInternetExplorer()) {
actualHeight = StringUtil.pixelToSize(elementsAndSizeKeeper.getOffsetHeight());
leftSide.setHeight(actualHeight);
rightSide.setHeight(actualHeight);
}
sizeKeeper.setWidth(StringUtil.pixelToSize(elementsPanel.getOffsetWidth()));
}
public void setSelected(boolean selected) {
this.selected = selected;
mainPanel.removeStyleName(selected ? "form_wholeForm":"form_wholeFormSelected");
mainPanel.addStyleName(selected ? "form_wholeFormSelected":"form_wholeForm");
container.setFocus(this.selected);
if(this.selected){
setFocusOnFirstAvailableField();
}
if(selected) {
DOM.addEventPreview(keyboardEventPreview);
} else {
DOM.removeEventPreview(keyboardEventPreview);
}
// we can show a context menu only on selected form
// in other case, a bug occurs: the pop-ups stick to the window
if(menuPopupShowRequest && isSelected()){
contextMenu.show();
menuPopupShowRequest = false;
}
contextMenu.setAbleToShow(selected);
}
private void setFocusOnFirstAvailableField() {
boolean foundField = false;
for(int i = 0, n = elementsGrid.getRowCount(); i < n; i++) {
for(int j = 0, m = elementsGrid.getCellCount(i); j < m; j++) {
QFormLayoutElement c = (QFormLayoutElement) elementsGrid.getWidget(i, j);
final HasFocus w = c.getFirstFocusableField();
if (w != null){
DeferredCommand.add(new Command() {
public void execute() {
w.setFocus(true);
}
});
foundField = true;
break;
}
}
if(foundField){
break;
}
}
}
private void subscribeEvents() {
container.addClickListener(new ClickListener() {
public void onClick(Widget sender) {
if(!selected) {
QFormController.Events.FORM_SELECTION_REQUESTED_EVENT.setData(model.getIndex());
formElementsEventSource.fireEvent(QFormController.Events.FORM_SELECTION_REQUESTED_EVENT);
}
}
});
// focus can be obtained in different ways
container.addFocusListener(new FocusListenerAdapter(){
public void onFocus(Widget sender) {
if(!selected) {
QFormController.Events.FORM_SELECTION_REQUESTED_EVENT.setData(model.getIndex());
formElementsEventSource.fireEvent(QFormController.Events.FORM_SELECTION_REQUESTED_EVENT);
}
}
});
}
private void setClearButtonCaption(String caption) {
if(clearButton != null) {
clearButton.setCaption(getUnderlined(caption));
clearButton.setTooltip(getKeyCodeCaption(caption));
presentButtons.remove(CLEAR_BUTTON_CANCEL_CAPTION);
presentButtons.remove(CLEAR_BUTTON_CLEAR_CAPTION);
presentButtons.add(caption);
}
}
/**
* This method apply state icon according form state.
*
* @param formState form state
*/
void setStateIcon(int formState) {
switch(formState) {
case FormState.EDIT_STATE:
stateIcon.setIconState(ICON_STATE_EDIT);
setClearButtonCaption(CLEAR_BUTTON_CANCEL_CAPTION);
break;
case FormState.NEW_STATE:
stateIcon.setIconState(ICON_STATE_NEW);
setClearButtonCaption(CLEAR_BUTTON_CANCEL_CAPTION);
break;
case FormState.SEARCH_STATE:
stateIcon.setIconState(ICON_STATE_SEARCH);
setClearButtonCaption(CLEAR_BUTTON_CLEAR_CAPTION);
break;
case FormState.SELECTED_STATE:
stateIcon.setIconState(ICON_STATE_SELECTED);
setClearButtonCaption(CLEAR_BUTTON_CLEAR_CAPTION);
break;
case FormState.REPORT_DESIGN_STATE:
stateIcon.setIconState(ICON_REPORT_DESIGN);
setClearButtonCaption(CLEAR_BUTTON_CLEAR_CAPTION);
break;
}
}
/**
* Returns a tooltip string
* @param buttonCaption
* @return a string like "Modifier + KeyCode"
*/
private String getKeyCodeCaption(String buttonCaption) {
if(keyCodes.containsKey(buttonCaption)){
return FORM_KEYCODE_PREFIX + ((Character)keyCodes.get(buttonCaption)).toString().toUpperCase();
}
return " ";
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -