Fixes #197 Фильтры: Сделать специальную кнопку ">>" которая открывает действия для изменения фильтра; Fixes #207 Кнопки ОК Отмена при редактировании фильтра перенести вниз

This commit is contained in:
Konstantin Krivopustov 2010-01-14 12:37:28 +00:00
parent 4576a007ea
commit 5c876bcea0
4 changed files with 203 additions and 159 deletions

View File

@ -37,6 +37,7 @@ import com.haulmont.cuba.web.app.folders.FolderEditWindow;
import com.haulmont.cuba.security.entity.User;
import com.haulmont.cuba.security.entity.SearchFolder;
import com.vaadin.data.Property;
import com.vaadin.terminal.Sizeable;
import com.vaadin.ui.*;
import com.vaadin.ui.Button;
import com.vaadin.ui.Label;
@ -66,12 +67,16 @@ public class WebFilter
private AbstractLayout paramsLayout;
private AbstractOrderedLayout editLayout;
private AbstractSelect select;
private Button createBtn;
private Button editBtn;
private Button deleteBtn;
private AbstractSelect actions;
private String nullActionId;
private String createActionId;
private String editActionId;
private String deleteActionId;
private String saveAsFolderActionId;
private Button applyBtn;
private CheckBox defaultCb;
private Button saveAsFolderBtn;
private boolean changingFilter;
private boolean editing;
@ -80,12 +85,16 @@ public class WebFilter
public WebFilter() {
component = new VerticalLayout();
component.setMargin(true);
component.setStyleName("generic-filter");
foldersPane = App.getInstance().getAppWindow().getFoldersPane();
HorizontalLayout topLayout = new HorizontalLayout();
topLayout.setSpacing(true);
select = new FilterSelect();
select.setWidth("300px");
select.setWidth(300, Sizeable.UNITS_PIXELS);
select.setStyleName("generic-filter-select");
select.setNullSelectionAllowed(true);
select.setImmediate(true);
select.addListener(new Property.ValueChangeListener() {
@ -96,7 +105,7 @@ public class WebFilter
filterEntity = (FilterEntity) select.getValue();
parseFilterXml();
updateButtons();
updateControls();
component.removeComponent(paramsLayout);
createParamsLayout();
component.addComponent(paramsLayout);
@ -113,61 +122,20 @@ public class WebFilter
});
topLayout.addComponent(applyBtn);
createBtn = WebComponentsHelper.createButton("icons/create.png");
createBtn.setCaption(MessageProvider.getMessage(AppConfig.getInstance().getMessagesPack(), "actions.Create"));
createBtn.addListener(new Button.ClickListener() {
public void buttonClick(Button.ClickEvent event) {
createFilterEntity();
parseFilterXml();
switchToEdit();
}
});
topLayout.addComponent(createBtn);
nullActionId = MessageProvider.getMessage(MESSAGES_PACK, "nullAction");
createActionId = MessageProvider.getMessage(MESSAGES_PACK, "ñreateAction");
editActionId = MessageProvider.getMessage(MESSAGES_PACK, "editAction");
deleteActionId = MessageProvider.getMessage(MESSAGES_PACK, "removeAction");
saveAsFolderActionId = MessageProvider.getMessage(MESSAGES_PACK, "saveAsFolderBtn");
editBtn = WebComponentsHelper.createButton("icons/edit.png");
editBtn.setCaption(MessageProvider.getMessage(AppConfig.getInstance().getMessagesPack(), "actions.Edit"));
editBtn.addListener(new Button.ClickListener() {
public void buttonClick(Button.ClickEvent event) {
switchToEdit();
}
});
topLayout.addComponent(editBtn);
deleteBtn = WebComponentsHelper.createButton("icons/remove.png");
deleteBtn.setCaption(MessageProvider.getMessage(AppConfig.getInstance().getMessagesPack(), "actions.Remove"));
deleteBtn.addListener(new Button.ClickListener() {
public void buttonClick(Button.ClickEvent event) {
getFrame().showOptionDialog(
MessageProvider.getMessage(MESSAGES_PACK, "deleteDlg.title"),
MessageProvider.getMessage(MESSAGES_PACK, "deleteDlg.msg"),
IFrame.MessageType.CONFIRMATION,
new Action[] {
new DialogAction(DialogAction.Type.YES) {
@Override
public void actionPerform(Component component) {
deleteFilterEntity();
select.removeItem(select.getValue());
if (!select.getItemIds().isEmpty()) {
select.select(select.getItemIds().iterator().next());
} else {
select.select(null);
}
}
},
new DialogAction(DialogAction.Type.NO)
}
);
}
});
topLayout.addComponent(deleteBtn);
foldersPane = App.getInstance().getAppWindow().getFoldersPane();
if (foldersPane != null) {
saveAsFolderBtn = WebComponentsHelper.createButton("icons/move.png");
saveAsFolderBtn.setCaption(MessageProvider.getMessage(MESSAGES_PACK, "saveAsFolderBtn"));
saveAsFolderBtn.addListener(new SaveAsFolderListener());
topLayout.addComponent(saveAsFolderBtn);
}
actions = new FilterSelect();
actions.setWidth(80, Sizeable.UNITS_PIXELS);
actions.setStyleName("generic-filter-actions");
actions.setImmediate(true);
actions.setNullSelectionAllowed(true);
actions.setNullSelectionItemId(nullActionId);
actions.addListener(new ActionsListener());
topLayout.addComponent(actions);
defaultCb = new CheckBox();
defaultCb.setCaption(MessageProvider.getMessage(MESSAGES_PACK, "defaultCb"));
@ -194,7 +162,24 @@ public class WebFilter
createParamsLayout();
component.addComponent(paramsLayout);
updateButtons();
updateControls();
}
private void fillActions() {
actions.removeAllItems();
actions.addItem(nullActionId);
if (!editing)
actions.addItem(createActionId);
if (filterEntity != null && !editing && checkGlobalFilterPermission()) {
actions.addItem(editActionId);
actions.addItem(deleteActionId);
}
if (foldersPane != null && filterEntity != null && !editing)
actions.addItem(saveAsFolderActionId);
}
private void apply() {
@ -300,7 +285,7 @@ public class WebFilter
select.setItemCaption(filterEntity, InstanceUtils.getInstanceName((Instance) filterEntity));
select.setValue(filterEntity);
updateButtons();
updateControls();
if (paramsLayout != null)
component.removeComponent(paramsLayout);
createParamsLayout();
@ -391,7 +376,7 @@ public class WebFilter
private void switchToUse() {
editing = false;
updateButtons();
updateControls();
component.removeComponent(editLayout);
createParamsLayout();
component.addComponent(paramsLayout);
@ -399,26 +384,23 @@ public class WebFilter
private void switchToEdit() {
editing = true;
updateButtons();
updateControls();
component.removeComponent(paramsLayout);
createEditLayout();
component.addComponent(editLayout);
}
private void updateButtons() {
private void updateControls() {
fillActions();
actions.setEnabled(!editing);
select.setEnabled(!editing);
createBtn.setEnabled(!editing);
applyBtn.setEnabled(!editing);
if (saveAsFolderBtn != null)
saveAsFolderBtn.setEnabled(filterEntity != null && !editing);
editBtn.setEnabled(filterEntity != null && !editing && checkGlobalFilterPermission());
deleteBtn.setEnabled(filterEntity != null && !editing && checkGlobalFilterPermission());
defaultCb.setEnabled(filterEntity != null && !editing);
if (filterEntity != null && !editing)
defaultCb.setValue(isTrue(filterEntity.getIsDefault()));
else
defaultCb.setValue(false);
}
private boolean checkGlobalFilterPermission() {
@ -495,7 +477,7 @@ public class WebFilter
if (defaultId.equals(filter.getId())) {
filter.setIsDefault(true);
select.setValue(filter);
updateButtons();
updateControls();
break;
}
}
@ -534,6 +516,115 @@ public class WebFilter
return false;
}
private void saveAsFolder() {
final SearchFolder folder = new SearchFolder();
folder.setName(filterEntity.getName());
folder.setFilterComponentId(filterEntity.getComponentId());
folder.setFilterXml(filterEntity.getXml());
folder.setUser(UserSessionClient.getUserSession().getUser());
final FolderEditWindow window = new FolderEditWindow(false, folder,
new Runnable() {
public void run() {
// search for existing folders with the same name
boolean found = false;
Collection<SearchFolder> folders = foldersPane.getSearchFolders();
for (final SearchFolder existingFolder : folders) {
if (ObjectUtils.equals(existingFolder.getName(), folder.getName())) {
found = true;
App.getInstance().getWindowManager().showOptionDialog(
MessageProvider.getMessage(AppConfig.getInstance().getMessagesPack(), "dialogs.Confirmation"),
MessageProvider.getMessage(MESSAGES_PACK, "saveAsFolderConfirmUpdate"),
IFrame.MessageType.CONFIRMATION,
new Action[] {
new DialogAction(DialogAction.Type.YES) {
@Override
public void actionPerform(Component component) {
// update existing folder
existingFolder.setFilterComponentId(folder.getFilterComponentId());
existingFolder.setFilterXml(folder.getFilterXml());
saveFolder(existingFolder);
}
},
new DialogAction(DialogAction.Type.NO) {
@Override
public void actionPerform(Component component) {
// create new folder
saveFolder(folder);
}
}
}
);
}
}
if (!found) {
// create new folder
saveFolder(folder);
}
}
}
);
window.addListener(new com.vaadin.ui.Window.CloseListener() {
public void windowClose(com.vaadin.ui.Window.CloseEvent e) {
App.getInstance().getAppWindow().removeWindow(window);
}
});
App.getInstance().getAppWindow().addWindow(window);
}
private void saveFolder(SearchFolder folder) {
foldersPane.saveFolder(folder);
foldersPane.refreshFolders();
}
private void delete() {
getFrame().showOptionDialog(
MessageProvider.getMessage(MESSAGES_PACK, "deleteDlg.title"),
MessageProvider.getMessage(MESSAGES_PACK, "deleteDlg.msg"),
IFrame.MessageType.CONFIRMATION,
new Action[] {
new DialogAction(DialogAction.Type.YES) {
@Override
public void actionPerform(Component component) {
deleteFilterEntity();
select.removeItem(select.getValue());
if (!select.getItemIds().isEmpty()) {
select.select(select.getItemIds().iterator().next());
} else {
select.select(null);
}
}
},
new DialogAction(DialogAction.Type.NO)
}
);
}
private class ActionsListener implements Property.ValueChangeListener {
public void valueChange(Property.ValueChangeEvent event) {
Object value = event.getProperty().getValue();
if (nullActionId.equals(value))
return;
if (createActionId.equals(value)) {
createFilterEntity();
parseFilterXml();
switchToEdit();
} else if (editActionId.equals(value)) {
switchToEdit();
} else if (deleteActionId.equals(value)) {
delete();
} else if (saveAsFolderActionId.equals(value)) {
saveAsFolder();
}
System.out.println(event.getProperty().getValue());
actions.setValue(nullActionId);
}
}
public static final Pattern LIKE_PATTERN = Pattern.compile("\\slike\\s+" + ParametersHelper.QUERY_PARAMETERS_RE);
private static class ParamWrapper implements HasValue {
@ -664,69 +755,4 @@ public class WebFilter
public void setFrame(IFrame frame) {
}
}
private class SaveAsFolderListener implements Button.ClickListener {
public void buttonClick(Button.ClickEvent event) {
final SearchFolder folder = new SearchFolder();
folder.setName(filterEntity.getName());
folder.setFilterComponentId(filterEntity.getComponentId());
folder.setFilterXml(filterEntity.getXml());
folder.setUser(UserSessionClient.getUserSession().getUser());
final FolderEditWindow window = new FolderEditWindow(false, folder,
new Runnable() {
public void run() {
// search for existing folders with the same name
boolean found = false;
Collection<SearchFolder> folders = foldersPane.getSearchFolders();
for (final SearchFolder existingFolder : folders) {
if (ObjectUtils.equals(existingFolder.getName(), folder.getName())) {
found = true;
App.getInstance().getWindowManager().showOptionDialog(
MessageProvider.getMessage(AppConfig.getInstance().getMessagesPack(), "dialogs.Confirmation"),
MessageProvider.getMessage(MESSAGES_PACK, "saveAsFolderConfirmUpdate"),
IFrame.MessageType.CONFIRMATION,
new Action[] {
new DialogAction(DialogAction.Type.YES) {
@Override
public void actionPerform(Component component) {
// update existing folder
existingFolder.setFilterComponentId(folder.getFilterComponentId());
existingFolder.setFilterXml(folder.getFilterXml());
saveFolder(existingFolder);
}
},
new DialogAction(DialogAction.Type.NO) {
@Override
public void actionPerform(Component component) {
// create new folder
saveFolder(folder);
}
}
}
);
}
}
if (!found) {
// create new folder
saveFolder(folder);
}
}
}
);
window.addListener(new com.vaadin.ui.Window.CloseListener() {
public void windowClose(com.vaadin.ui.Window.CloseEvent e) {
App.getInstance().getAppWindow().removeWindow(window);
}
});
App.getInstance().getAppWindow().addWindow(window);
}
private void saveFolder(SearchFolder folder) {
foldersPane.saveFolder(folder);
foldersPane.refreshFolders();
}
}
}

View File

@ -51,6 +51,7 @@ public class FilterEditor {
private static final String EDITOR_WIDTH = "600px";
private static List<String> defaultExcludedProps = Arrays.asList("version");
private CheckBox globalCb;
private Button saveBtn;
public FilterEditor(final WebFilter webFilter, FilterEntity filterEntity, Element filterDescriptor)
{
@ -71,14 +72,18 @@ public class FilterEditor {
layout.setMargin(true, false, false, false);
layout.setWidth(EDITOR_WIDTH);
GridLayout grid = new GridLayout(2, 2);
grid.setWidth("100%");
grid.setSpacing(true);
GridLayout topGrid = new GridLayout(2, 1);
topGrid.setWidth("100%");
topGrid.setSpacing(true);
GridLayout bottomGrid = new GridLayout(2, 1);
bottomGrid.setWidth("100%");
bottomGrid.setSpacing(true);
HorizontalLayout controlLayout = new HorizontalLayout();
controlLayout.setSpacing(true);
Button saveBtn = WebComponentsHelper.createButton("icons/ok.png");
saveBtn = WebComponentsHelper.createButton("icons/ok.png");
saveBtn.setCaption(MessageProvider.getMessage(AppConfig.getInstance().getMessagesPack(), "actions.Ok"));
saveBtn.addListener(new Button.ClickListener() {
public void buttonClick(Button.ClickEvent event) {
@ -97,7 +102,7 @@ public class FilterEditor {
});
controlLayout.addComponent(cancelBtn);
grid.addComponent(controlLayout, 0, 0);
bottomGrid.addComponent(controlLayout, 0, 0);
globalCb = new CheckBox();
globalCb.setCaption(getMessage("FilterEditor.global"));
@ -105,8 +110,8 @@ public class FilterEditor {
globalCb.setEnabled(UserSessionClient.getUserSession().isSpecificPermitted("cuba.gui.filter.global"));
controlLayout.addComponent(globalCb);
grid.addComponent(globalCb, 1, 0);
grid.setComponentAlignment(globalCb, Alignment.MIDDLE_RIGHT);
bottomGrid.addComponent(globalCb, 1, 0);
bottomGrid.setComponentAlignment(globalCb, Alignment.MIDDLE_RIGHT);
HorizontalLayout nameLayout = new HorizontalLayout();
nameLayout.setSpacing(true);
@ -119,21 +124,23 @@ public class FilterEditor {
nameField.setWidth("200px");
nameLayout.addComponent(nameField);
grid.addComponent(nameLayout, 0, 1);
topGrid.addComponent(nameLayout, 0, 0);
AbstractLayout addLayout = initAddSelect();
grid.addComponent(addLayout, 1, 1);
grid.setComponentAlignment(addLayout, Alignment.MIDDLE_RIGHT);
topGrid.addComponent(addLayout, 1, 0);
topGrid.setComponentAlignment(addLayout, Alignment.MIDDLE_RIGHT);
layout.addComponent(grid);
layout.addComponent(topGrid);
HorizontalLayout mainLayout = new HorizontalLayout();
mainLayout.setSpacing(true);
initTable(mainLayout);
layout.addComponent(mainLayout);
layout.addComponent(bottomGrid);
updateControls();
}
private AbstractLayout initAddSelect() {
@ -241,11 +248,18 @@ public class FilterEditor {
},
condition
);
updateControls();
}
private void deleteCondition(Condition condition) {
conditions.remove(condition);
table.removeItem(condition);
updateControls();
}
private void updateControls() {
saveBtn.setEnabled(!conditions.isEmpty());
}
private Button createDeleteConditionBtn(final Condition condition) {

View File

@ -1,9 +1,11 @@
applyBtn=Apply
createBtn=Create
editBtn=Edit
deleteBtn=Delete
сreateAction=Create filter
editAction=Edit filter
removeAction=Remove filter
defaultCb=Default
saveAsFolderBtn=Folder
saveAsFolderBtn=Save filter to folders
nullAction=More...
saveAsFolderConfirmUpdate=Folder with the same name already exists. Do you want to update the existing folder?

View File

@ -1,9 +1,11 @@
applyBtn=Применить
createBtn=Создать
editBtn=Редакт.
deleteBtn=Удалить
сreateAction=Создать фильтр
editAction=Изменить фильтр
removeAction=Удалить фильтр
defaultCb=По умолчанию
saveAsFolderBtn=В папки
saveAsFolderBtn=Сохранить фильтр в папки
nullAction=Еще...
newFilterName=Новый фильтр
deleteDlg.title=Подтверждение