📄 qformviewimpl.java
字号:
mainPanel.setWidget(1, 0, leftSide);
mainPanel.setWidget(1, 1, elementsAndSizeKeeper);
mainPanel.setWidget(1, 2, rightSide);
mainPanel.setWidget(2, 0, leftBottom);
mainPanel.setWidget(2, 1, bottomSide);
mainPanel.setWidget(2, 2, rightBottom);
mainPanel.setCellPadding(0);
mainPanel.setCellSpacing(0);
minimizeButton.addClickListener(this);
mainPanel.setStyleName(WHOLE_FORM_STYLE);
container.setWidget(mainPanel);
initWidget(container);
}
private void createMenu() {
MenuItemMeta[] menuItems;
ContextMenuMeta menuMeta;
contextMenu = new MenuPopup(menuButton);
menuMeta = model.getContextMenuMeta();
if(menuMeta != null) {
menuItems = menuMeta.getMenuItems();
if(menuItems != null) {
for(int i = 0; i < menuItems.length; i++) {
Event event = new Event(menuItems[i].getMenuItemID());
ButtonData data = new ButtonData(menuItems[i].getCaption());
contextMenu.addButton(event, data);
}
}
}
// Doing this to eliminate the bug when context menus stick to the window
contextMenu.setAbleToShow(false);
contextMenu.getEventSource().addEventListener(new EventListener(){
public void onEvent(Event event, Widget sender) {
if(event == MenuPopup.Events.MENUPOPUP_SHOW_REQUEST){
menuPopupShowRequest = true;
}
}
});
}
public void onClick(Widget sender) {
if(sender == minimizeButton) {
minimized = !minimized;
minimizeButton.setButtonState(minimized ? MINIMIZE_BUTTON_MAX_STATE:MINIMIZE_BUTTON_MIN_STATE);
if (Application.isInternetExplorer()) {
leftSide.setHeight(minimized ? "1px" : actualHeight);
rightSide.setHeight(minimized ? "1px" : actualHeight);
}
elementsPanel.setVisible(!minimized);
getParent().setHeight("0px"); // collapse freed space in FireFox
}
}
protected void addWidget(int xPosition, int yPosition, int width, int height, QFormLayoutElement controlView) {
addWidget(xPosition, yPosition, width, height, controlView, elementsGrid);
}
protected void addWidget(int xPosition, int yPosition, int width, int height, QFormLayoutElement controlView, FlexTable grid) {
controlView.setColSpan(width);
controlView.setRowSpan(height);
grid.setWidget(yPosition, xPosition, controlView);
grid.getFlexCellFormatter().setColSpan(yPosition, xPosition, width);
grid.getFlexCellFormatter().setRowSpan(yPosition, xPosition, height);
}
public void setEnabledForSearch() {
Set ids = controls.keySet();
for(Iterator iterator = ids.iterator(); iterator.hasNext();) {
((QFormElement) controls.get(iterator.next())).getBaseView().setEnabledForSearch();
}
}
public void setEnabledForEdit() {
Set ids = controls.keySet();
for(Iterator iterator = ids.iterator(); iterator.hasNext();) {
((QFormElement) controls.get(iterator.next())).getBaseView().setEnabledForEdit();
}
}
public void setEnabledForNew() {
Set ids = controls.keySet();
for(Iterator iterator = ids.iterator(); iterator.hasNext();) {
((QFormElement) controls.get(iterator.next())).getBaseView().setEnabledForNew();
}
}
public void setEnabledForReportDesign() {
Set ids = controls.keySet();
for(Iterator iterator = ids.iterator(); iterator.hasNext();) {
((QFormElement) controls.get(iterator.next())).getBaseView().setModeRepordDesign();
}
}
public void disable() {
Set ids = controls.keySet();
for(Iterator iterator = ids.iterator(); iterator.hasNext();) {
((QFormElement) controls.get(iterator.next())).getBaseView().disable();
}
}
protected void setCommonActionEnabled(Event[] commonFormsActions, boolean isEnabled) {
for(int i = 0; i < commonFormsActions.length; i++) {
setCommonActionEnabled(commonFormsActions[i], isEnabled);
}
}
protected void setCommonActionEnabled(Event action, boolean isEnabled) {
if(QFormController.Events.FORM_NEW_BUTTON_EVENT.equals(action) && newButton != null) {
newButton.setEnabled(isEnabled);
} else if((QFormController.Events.FORM_CHANGE_BUTTON_EVENT.equals(action) || QFormController.Events
.FORM_UPDATE_BUTTON_EVENT
.equals(action)) && changeOrUpdateButton != null) {
changeOrUpdateButton.setEnabled(isEnabled);
} else if(QFormController.Events.FORM_CLEAR_BUTTON_EVENT.equals(action) && clearButton != null) {
clearButton.setEnabled(isEnabled);
} else if(QFormController.Events.FORM_SEARCH_BUTTON_EVENT.equals(action) && searchButton != null) {
searchButton.setEnabled(isEnabled);
}
}
private static class ButtonLayoutInfo {
private final int row;
private final int col;
private final int colspan;
private final int rowspan;
public ButtonLayoutInfo(int row, int col, int colspan, int rowspan) {
this.row = row;
this.col = col;
this.colspan = colspan;
this.rowspan = rowspan;
}
public ButtonLayoutInfo(int row, int col) {
this(row, col, 1, 1);
}
}
private final static boolean isASystemButton(String fieldId) {
return fieldId.equalsIgnoreCase(QFormController.FORM_NEW_BUTTON) ||
fieldId.equalsIgnoreCase(QFormController.FORM_SEARCH_BUTTON) ||
fieldId.equalsIgnoreCase(QFormController.FORM_CHANGE_BUTTON) ||
fieldId.equalsIgnoreCase(QFormController.FORM_UPDATE_BUTTON) ||
fieldId.equalsIgnoreCase(QFormController.FORM_CHANGE_OR_UPDATE_BUTTON) ||
fieldId.equalsIgnoreCase(QFormController.FORM_CLEAR_BUTTON);
}
private QButton createButton(FormButtonMeta buttonMeta) {
String buttonCaption = buttonMeta.getCaption();
if(buttonCaption.length() != 0){
presentButtons.add(buttonCaption);
}
String buttonId = buttonMeta.getId();
Event event;
QButton result;
boolean isWidthFixed = buttonCaption.length() < 8;
if(buttonId.equals(QFormController.FORM_NEW_BUTTON)) {
commonActionPanel.removeButton(newButton);
if(buttonCaption.length() != 0){
newButton = new QButton(getUnderlined(buttonCaption), getKeyCodeCaption(buttonCaption), getFormLabelsOrientation(), isWidthFixed);
} else {
newButton = new QButton(getUnderlined(NEW_BUTTON_CAPTION), getKeyCodeCaption(NEW_BUTTON_CAPTION), getFormLabelsOrientation(), isWidthFixed);
presentButtons.add(NEW_BUTTON_CAPTION);
}
event = QFormController.Events.FORM_NEW_BUTTON_EVENT;
result = newButton;
} else if ((buttonId.equals(QFormController.FORM_CHANGE_BUTTON)) ||
(buttonId.equals(QFormController.FORM_UPDATE_BUTTON)) ||
(buttonId.equals(QFormControllerImpl.FORM_CHANGE_OR_UPDATE_BUTTON))) {
commonActionPanel.removeButton(changeOrUpdateButton);
if(buttonCaption.length() != 0) {
changeOrUpdateButton = new QButton(getUnderlined(buttonCaption), getKeyCodeCaption(buttonCaption), getFormLabelsOrientation(), isWidthFixed);
} else {
changeOrUpdateButton = new QButton(getUnderlined(CHANGE_BUTTON_CAPTION), getKeyCodeCaption(CHANGE_BUTTON_CAPTION), getFormLabelsOrientation(), isWidthFixed);
presentButtons.add(CHANGE_BUTTON_CAPTION);
}
event = QFormController.Events.FORM_CHANGE_BUTTON_EVENT;
result = changeOrUpdateButton;
} else if(buttonId.equals(QFormController.FORM_CLEAR_BUTTON)) {
commonActionPanel.removeButton(clearButton);
if(buttonCaption.length() != 0) {
clearButton = new QButton(getUnderlined(buttonCaption), getKeyCodeCaption(buttonCaption), getFormLabelsOrientation(), isWidthFixed);
} else {
clearButton = new QButton(getUnderlined(CLEAR_BUTTON_CLEAR_CAPTION), getKeyCodeCaption(CLEAR_BUTTON_CLEAR_CAPTION), getFormLabelsOrientation(), isWidthFixed);
presentButtons.add(CLEAR_BUTTON_CLEAR_CAPTION);
}
event = QFormController.Events.FORM_CLEAR_BUTTON_EVENT;
result = clearButton;
} else if(buttonId.equals(QFormController.FORM_SEARCH_BUTTON)) {
commonActionPanel.removeButton(searchButton);
if(buttonCaption.length() != 0) {
searchButton = new QButton(getUnderlined(buttonCaption), getKeyCodeCaption(buttonCaption), getFormLabelsOrientation(), isWidthFixed);
} else {
searchButton = new QButton(getUnderlined(SEARCH_BUTTON_CAPTION), getKeyCodeCaption(SEARCH_BUTTON_CAPTION), getFormLabelsOrientation(), isWidthFixed);
presentButtons.add(SEARCH_BUTTON_CAPTION);
}
event = QFormController.Events.FORM_SEARCH_BUTTON_EVENT;
result = searchButton;
} else {
result = new QButton(buttonCaption, getFormLabelsOrientation(),
buttonMeta.getButtonType(), buttonMeta.getIcon(),
buttonMeta.getCaptionStyle(), isWidthFixed);
event = new Event(new QButton.CustomButtonEventData(buttonId));
customButtons.put(buttonId, result);
}
commonActionPanel.addButton(event, result);
return result;
}
private ButtonLayoutInfo findButtonInLayout(String buttonId) {
for(int rowIdx = 0; rowIdx < getLayoutMeta().getRows().length; rowIdx++) {
FormLayoutMeta.Row row = getLayoutMeta().getRows()[rowIdx];
for(int colIdx = 0; colIdx < row.getColsCount(); colIdx++) {
FormLayoutMeta.Col col = row.getCols()[colIdx];
if(col.getFieldID().equals(buttonId)) {
return new ButtonLayoutInfo(rowIdx, colIdx, col.getColspan(), col.getRowspan());
}
}
}
return null;
}
private void createButtonsMap(Map buttonsForPanel, Map buttonsForGrid) {
if(getLayoutMeta() != null) {
int row = 0;
int col = 0;
for(Iterator i = buttonsMeta.iterator(); i.hasNext();) {
FormButtonMeta buttonMeta = (FormButtonMeta) i.next();
QButton button = createButton(buttonMeta);
ButtonLayoutInfo buttonLayout = findButtonInLayout(buttonMeta.getId());
if(buttonLayout != null) {
buttonsForGrid.put(button, buttonLayout);
} else {
buttonsForPanel.put(button, new ButtonLayoutInfo(row, col++));
if(col == 2) {
col = 0;
row++;
}
}
}
} else {
int row = 0;
int col = 0;
for(Iterator i = buttonsMeta.iterator(); i.hasNext();) {
FormButtonMeta buttonMeta = (FormButtonMeta) i.next();
QButton button = createButton(buttonMeta);
buttonsForPanel.put(button, new ButtonLayoutInfo(row, col++));
if(col == 2) {
col = 0;
row++;
}
}
}
}
public void dataStructureChanged() {
initFormLayoutUI();
}
private void initFormLayoutUI() {
controls.clear();
customButtons.clear();
presentButtons.clear();
setCaption(model.getFormTitle());
Map buttonsForPanel = new HashMap();
Map buttonsForGrid = new HashMap();
createButtonsMap(buttonsForPanel, buttonsForGrid);
if(getLayoutMeta() == null) {
fillFormFromModel();
} else {
fillFormFromLayoutMeta();
}
setupButtons(buttonsForPanel, commonActionPanel.getInternalGrid());
setupButtons(buttonsForGrid, elementsGrid);
activateLinks();
}
private void setupButtons(Map buttons, FlexTable grid) {
for(Iterator it = buttons.keySet().iterator(); it.hasNext();) {
QButton button = (QButton) it.next();
ButtonLayoutInfo layoutInfo = (ButtonLayoutInfo) buttons.get(button);
addWidget(layoutInfo.col, layoutInfo.row, layoutInfo.colspan, layoutInfo.rowspan, button, grid);
}
}
/**
* Creates form using specified FormLayoutMeta instance.
*/
private void fillFormFromLayoutMeta() {
Set createdHiddenControls = new HashSet();
for(int rowIdx = 0; rowIdx < getLayoutMeta().getRows().length; rowIdx++) {
FormLayoutMeta.Row row = getLayoutMeta().getRows()[rowIdx];
for(int colIdx = 0; colIdx < row.getColsCount(); colIdx++) {
FormLayoutMeta.Col col = row.getCols()[colIdx];
QFormLayoutElement control;
if(col.getFieldID().equals("")) {
control = new QErrorLabel(getFormLabelsOrientation(), "");
} else {
if(model.getElementMeta(col.getFieldID()) != null) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -