Fixes #570 (Change sys_folder table) , Fixes #568: Копирование папок поиска, в том числе системных

This commit is contained in:
Konstantin Devyatkin 2011-03-03 09:33:33 +00:00
parent 227364cdd8
commit 0df2f2fe90
11 changed files with 169 additions and 79 deletions

View File

@ -0,0 +1,3 @@
-- $Id$
-- Description: Rename double_name column to tab_name
ALTER TABLE sys_folder RENAME COLUMN double_name to tab_name;

View File

@ -0,0 +1,7 @@
-- $Id$
-- Description: delete code column in sys_folder
UPDATE sys_folder as folder1
SET name = code
WHERE name IS NULL^
ALTER TABLE sys_folder DROP COLUMN code;

View File

@ -0,0 +1,6 @@
-- $Id$
-- Description: update tab_name in sys_folder : for search folder,
-- wich haven't tab name,put to tab name name of folder + '.tabName'
UPDATE sys_folder
SET tab_name = name || '.tabName'
WHERE tab_name IS NULL AND type='S';

View File

@ -15,7 +15,7 @@ import javax.persistence.Entity;
@Entity(name = "core$Folder")
@Table(name = "SYS_FOLDER")
@Inheritance(strategy= InheritanceType.JOINED)
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "TYPE", discriminatorType = DiscriminatorType.STRING)
@DiscriminatorValue("F")
public class Folder extends StandardEntity {
@ -35,11 +35,8 @@ public class Folder extends StandardEntity {
@Transient
protected String itemStyle = null;
@Column(name="CODE")
protected String code;
@Column(name="DOUBLE_NAME")
protected String doubleName;
@Column(name = "TAB_NAME")
protected String tabName;
public Folder getParent() {
return parent;
@ -69,27 +66,19 @@ public class Folder extends StandardEntity {
this.sortOrder = sortOrder;
}
public String getItemStyle(){
public String getItemStyle() {
return itemStyle;
}
public void setItemStyle(String itemStyle){
public void setItemStyle(String itemStyle) {
this.itemStyle = itemStyle;
}
public String getCode() {
return code;
public String getTabName() {
return tabName;
}
public void setCode(String code) {
this.code = code;
}
public String getDoubleName() {
return doubleName;
}
public void setDoubleName(String doubleName) {
this.doubleName = doubleName;
public void setTabName(String tabName) {
this.tabName = tabName;
}
}

View File

@ -18,7 +18,7 @@ import javax.persistence.*;
@Entity(name = "sec$SearchFolder")
@Table(name = "SEC_SEARCH_FOLDER")
@PrimaryKeyJoinColumn(name="FOLDER_ID", referencedColumnName = "ID")
@PrimaryKeyJoinColumn(name = "FOLDER_ID", referencedColumnName = "ID")
@DiscriminatorValue("S")
public class SearchFolder extends AbstractSearchFolder {
@ -53,14 +53,7 @@ public class SearchFolder extends AbstractSearchFolder {
@Override
public String getCaption() {
if (code != null) {
return getLocName();
} else {
return name;
}
return MessageProvider.getMessage(MessageUtils.getMessagePack(), name);
}
public String getLocName(){
return code != null ? MessageProvider.getMessage(MessageUtils.getMessagePack(), code) : code;
}
}

View File

@ -64,7 +64,7 @@ public class AppFolderEditWindow extends FolderEditWindow {
okBtn.addListener(new Button.ClickListener() {
public void buttonClick(Button.ClickEvent event) {
AppFolderEditWindow.this.folder.setName((String) nameField.getValue());
AppFolderEditWindow.this.folder.setDoubleName((String) doubleNameField.getValue());
AppFolderEditWindow.this.folder.setTabName((String) tabNameField.getValue());
if (sortOrderField.getValue() == null || "".equals(sortOrderField.getValue())) {
AppFolderEditWindow.this.folder.setSortOrder(null);

View File

@ -32,7 +32,7 @@ public class FolderEditWindow extends Window {
protected Folder folder;
protected String messagesPack;
protected TextField nameField;
protected TextField doubleNameField;
protected TextField tabNameField;
protected Select parentSelect;
protected TextField sortOrderField;
protected Select presentation;
@ -64,11 +64,11 @@ public class FolderEditWindow extends Window {
nameField.setValue(folder.getName());
layout.addComponent(nameField);
doubleNameField = new TextField();
doubleNameField.setCaption(getMessage("folders.folderEditWindow.doubleNameField"));
doubleNameField.setWidth(250, Sizeable.UNITS_PIXELS);
doubleNameField.setValue(StringUtils.trimToEmpty(folder.getDoubleName()));
layout.addComponent(doubleNameField);
tabNameField = new TextField();
tabNameField.setCaption(getMessage("folders.folderEditWindow.tabNameField"));
tabNameField.setWidth(250, Sizeable.UNITS_PIXELS);
tabNameField.setValue(StringUtils.trimToEmpty(folder.getTabName()));
layout.addComponent(tabNameField);
parentSelect = new Select();
parentSelect.setCaption(getMessage("folders.folderEditWindow.parentSelect"));
@ -104,8 +104,7 @@ public class FolderEditWindow extends Window {
layout.addComponent(sortOrderField);
if (UserSessionClient.getUserSession().isSpecificPermitted("cuba.gui.searchFolder.global")
&& folder instanceof SearchFolder)
{
&& folder instanceof SearchFolder) {
globalCb = new CheckBox(getMessage("folders.folderEditWindow.global"));
globalCb.setValue(((SearchFolder) folder).getUser() == null);
layout.addComponent(globalCb);
@ -129,11 +128,11 @@ public class FolderEditWindow extends Window {
buttonsLayout.addComponent(cancelBtn);
}
protected void initButtonOkListener(){
protected void initButtonOkListener() {
okBtn.addListener(new Button.ClickListener() {
public void buttonClick(Button.ClickEvent event) {
public void buttonClick(Button.ClickEvent event) {
FolderEditWindow.this.folder.setName((String) nameField.getValue());
FolderEditWindow.this.folder.setDoubleName((String) doubleNameField.getValue());
FolderEditWindow.this.folder.setTabName((String) tabNameField.getValue());
if (sortOrderField.getValue() == null || "".equals(sortOrderField.getValue())) {
FolderEditWindow.this.folder.setSortOrder(null);
@ -160,10 +159,13 @@ public class FolderEditWindow extends Window {
FolderEditWindow.this.folder.setParent(null);
if (globalCb != null) {
if (BooleanUtils.isTrue((Boolean) globalCb.getValue()))
if (BooleanUtils.isTrue((Boolean) globalCb.getValue())) {
((SearchFolder) FolderEditWindow.this.folder).setUser(null);
else
} else {
((SearchFolder) FolderEditWindow.this.folder).setUser(UserSessionClient.getUserSession().getCurrentOrSubstitutedUser());
}
} else {
((SearchFolder) FolderEditWindow.this.folder).setUser(UserSessionClient.getUserSession().getCurrentOrSubstitutedUser());
}
if (presentation != null) {
@ -187,9 +189,9 @@ public class FolderEditWindow extends Window {
FoldersService service = ServiceLocator.lookup(FoldersService.JNDI_NAME);
List<SearchFolder> list = service.loadSearchFolders();
for (SearchFolder folder : list) {
if (!folder.equals(this.folder) && folder.getCode() == null) {
if (!folder.equals(this.folder)) {
parentSelect.addItem(folder);
parentSelect.setItemCaption(folder, folder.getName());
parentSelect.setItemCaption(folder, folder.getCaption());
}
}
}

View File

@ -45,7 +45,6 @@ import com.vaadin.ui.*;
import com.vaadin.ui.Component;
import com.vaadin.ui.Label;
import com.vaadin.ui.Tree;
import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -53,8 +52,6 @@ import org.apache.commons.logging.LogFactory;
import java.util.*;
import java.util.List;
import com.haulmont.cuba.web.toolkit.Timer;
@SuppressWarnings("serial")
public class FoldersPane extends VerticalLayout {
@ -474,14 +471,12 @@ public class FoldersPane extends VerticalLayout {
Map<String, Object> params = new HashMap<String, Object>();
params.put("disableAutoRefresh", true);
if (!StringUtils.isBlank(folder.getCode()))
params.put("description", MessageProvider.getMessage(messagesPack, folder.getCode() + ".doubleName"));
else if (folder instanceof AppFolder)
if (!StringUtils.isBlank(folder.getTabName())) {
params.put("description", MessageProvider.getMessage(messagesPack, folder.getTabName()));
} else {
params.put("description", MessageProvider.getMessage(messagesPack, folder.getName()));
else if (!StringUtils.isBlank(folder.getDoubleName()))
params.put("description", folder.getDoubleName());
else
params.put("description", folder.getName());
}
params.put("disableApplySettings", true);
Window window = App.getInstance().getWindowManager().openWindow(windowInfo,
@ -498,10 +493,8 @@ public class FoldersPane extends VerticalLayout {
filterEntity.setComponentId(folder.getFilterComponentId());
if (folder instanceof AppFolder)
filterEntity.setName(((AppFolder) folder).getLocName());
else if (folder.getCode() == null)
filterEntity.setName(folder.getName());
else
filterEntity.setName(folder.getCaption());
filterEntity.setName(folder.getName());
filterEntity.setXml(folder.getFilterXml());
filterComponent.setFilterEntity(filterEntity);
@ -585,7 +578,7 @@ public class FoldersPane extends VerticalLayout {
public Action[] getActions(Object target, Object sender) {
if (target instanceof Folder) {
if (UserSessionClient.getUserSession().isSpecificPermitted("cuba.gui.appFolder.global")) {
return new Action[]{new OpenAction(), new CreateAction(true), new EditAction(), new RemoveAction()};
return new Action[]{new OpenAction(), new CreateAction(true), new CopyAction(), new EditAction(), new RemoveAction()};
} else {
return new Action[]{new OpenAction()};
}
@ -607,18 +600,73 @@ public class FoldersPane extends VerticalLayout {
public Action[] getActions(Object target, Object sender) {
if (target instanceof SearchFolder) {
if (StringUtils.isBlank(((SearchFolder) target).getFilterComponentId()))
return new Action[]{new CreateAction(false), new EditAction(), new RemoveAction()};
else {
if (((SearchFolder) target).getCode() == null)
return new Action[]{new OpenAction(), new CreateAction(false), new EditAction(), new RemoveAction()};
else
return new Action[]{new OpenAction(), new CreateAction(false)};
if (isGlobalFolder((SearchFolder) target)) {
if (isFilterFolder((SearchFolder) target)) {
if (isGlobalSearchFolderPermitted()) {
return createAllActions();
} else {
return createOpenCreateAction();
}
} else {
if (isGlobalSearchFolderPermitted()) {
return createWithoutOpenActions();
} else {
return createOnlyCreateAction();
}
}
} else {
if (isFilterFolder((SearchFolder) target)) {
if (isOwner((SearchFolder) target)) {
return createAllActions();
} else {
return createOpenCreateAction();
}
} else {
if (isOwner((SearchFolder) target)) {
return createWithoutOpenActions();
} else {
return createOnlyCreateAction();
}
}
}
} else
return new Action[]{new CreateAction(false)};
} else {
return createOnlyCreateAction();
}
}
private boolean isGlobalFolder(SearchFolder folder) {
return (folder.getUser() == null);
}
private boolean isFilterFolder(SearchFolder folder) {
return (folder.getFilterComponentId() != null);
}
private boolean isOwner(SearchFolder folder) {
return UserSessionClient.getUserSession().getUser().equals(folder.getUser());
}
private boolean isGlobalSearchFolderPermitted() {
return (UserSessionClient.getUserSession().isSpecificPermitted("cuba.gui.searchFolder.global"));
}
private Action[] createAllActions() {
return new Action[]{new OpenAction(), new CopyAction(), new CreateAction(false), new EditAction(), new RemoveAction()};
}
private Action[] createWithoutOpenActions() {
return new Action[]{new CreateAction(false), new EditAction(), new RemoveAction()};
}
private Action[] createOnlyCreateAction() {
return new Action[]{new CreateAction(false)};
}
private Action[] createOpenCreateAction() {
return new Action[]{new OpenAction(), new CreateAction(false), new CopyAction()};
}
}
protected abstract class FolderAction extends Action {
@ -655,7 +703,7 @@ public class FoldersPane extends VerticalLayout {
final Folder newFolder = isAppFolder ? (new AppFolder()) : (new SearchFolder());
newFolder.setName("");
newFolder.setDoubleName("");
newFolder.setTabName("");
newFolder.setParent(folder);
final FolderEditWindow window = AppFolderEditWindow.create(isAppFolder, true, newFolder, null,
new Runnable() {
@ -674,6 +722,37 @@ public class FoldersPane extends VerticalLayout {
}
}
protected class CopyAction extends FolderAction {
public CopyAction() {
super(MessageProvider.getMessage(messagesPack, "folders.copyFolderAction"));
}
public void perform(final Folder folder) {
AbstractSearchFolder oldFolder = (AbstractSearchFolder) folder;
final AbstractSearchFolder newFolder = (folder instanceof AppFolder) ? (new AppFolder()) : (new SearchFolder());
newFolder.setCreatedBy(folder.getCreatedBy());
newFolder.setCreateTs(folder.getCreateTs());
newFolder.setDeletedBy(folder.getDeletedBy());
newFolder.setDeleteTs(folder.getDeleteTs());
newFolder.setFilterComponentId(oldFolder.getFilterComponentId());
newFolder.setFilterXml(oldFolder.getFilterXml());
newFolder.setName(oldFolder.getCaption());
newFolder.setTabName(oldFolder.getTabName());
newFolder.setParent(oldFolder.getParent());
newFolder.setItemStyle(oldFolder.getItemStyle());
newFolder.setSortOrder(oldFolder.getSortOrder());
if (newFolder instanceof SearchFolder) {
((SearchFolder) newFolder).setUser(UserSessionClient.getUserSession().getUser());
} else {
((AppFolder) newFolder).setQuantityScript(((AppFolder) oldFolder).getQuantityScript());
((AppFolder) newFolder).setVisibilityScript(((AppFolder) oldFolder).getVisibilityScript());
}
new EditAction().perform(newFolder);
}
}
protected class EditAction extends FolderAction {
public EditAction() {

View File

@ -218,9 +218,17 @@ public class WebFilter
return;
if (checkGlobalFilterPermission()) {
if (filterEntity.getFolder() == null || filterEntity.getFolder() instanceof SearchFolder)
if ((filterEntity.getFolder() == null) || (filterEntity.getFolder() instanceof SearchFolder) ||
((filterEntity.getFolder() instanceof AppFolder) && checkGlobalAppFolderPermission()))
actions.addAction(new EditAction());
if (filterEntity.getCode() == null && filterEntity.getFolder() == null)
actions.addAction(new DeleteAction());
} else {
if (filterEntity.getFolder() instanceof SearchFolder)
if ((UserSessionClient.getUserSession().getUser().equals(((SearchFolder) filterEntity.getFolder()).getUser())))
actions.addAction(new EditAction());
if (filterEntity.getCode() == null && filterEntity.getFolder() == null)
actions.addAction(new DeleteAction());
}
@ -487,10 +495,11 @@ public class WebFilter
name = "";
AbstractSearchFolder folder = filterEntity.getFolder();
if (folder != null) {
if (!StringUtils.isBlank(folder.getDoubleName()))
name = folder.getDoubleName();
else if (!StringUtils.isBlank(folder.getCode()))
name = MessageProvider.getMessage(mainMessagesPack, folder.getCode() + ".doubleName");
if (!StringUtils.isBlank(folder.getTabName()))
name = MessageProvider.getMessage(mainMessagesPack, folder.getTabName());
else if (!StringUtils.isBlank(folder.getName())) {
name = MessageProvider.getMessage(mainMessagesPack, folder.getName());
}
name = MessageProvider.getMessage(MESSAGES_PACK, "folderPrefix") + " " + name;
}
return name;
@ -741,11 +750,11 @@ public class WebFilter
final AbstractSearchFolder folder = isAppFolder ? (new AppFolder()) : (new SearchFolder());
if (filterEntity.getCode() == null) {
folder.setName(filterEntity.getName());
folder.setDoubleName(filterEntity.getName());
folder.setTabName(filterEntity.getName());
} else {
String name = MessageProvider.getMessage(mainMessagesPack, filterEntity.getCode());
folder.setName(name);
folder.setDoubleName(name);
folder.setTabName(name);
}
folder.setFilterComponentId(filterEntity.getComponentId());
folder.setFilterXml(filterEntity.getXml());

View File

@ -70,13 +70,14 @@ folders.searchFoldersRoot=Search Folders
folders.openFolderAction=Open
folders.createFolderAction=Create
folders.copyFolderAction=Copy
folders.editFolderAction=Rename
folders.removeFolderAction=Remove
folders.folderEditWindow=Edit Folder
folders.folderEditWindow.adding=Add Folder
folders.folderEditWindow.nameField=Folder Name
folders.folderEditWindow.doubleNameField=Screen Caption
folders.folderEditWindow.tabNameField=Screen Caption
folders.folderEditWindow.parentSelect=Parent Folder
folders.folderEditWindow.sortOrder=Order No
folders.folderEditWindow.invalidSortOrder=Invalid order no

View File

@ -67,13 +67,14 @@ folders.searchFoldersRoot=Папки поиска
folders.openFolderAction=Открыть
folders.createFolderAction=Создать
folders.copyFolderAction=Копировать
folders.editFolderAction=Изменить
folders.removeFolderAction=Удалить
folders.folderEditWindow=Изменение папки
folders.folderEditWindow.adding=Добавление папки
folders.folderEditWindow.nameField=Наименование папки
folders.folderEditWindow.doubleNameField=Заголовок окна
folders.folderEditWindow.tabNameField=Заголовок окна
folders.folderEditWindow.parentSelect=Родительская папка
folders.folderEditWindow.sortOrder=Порядковый номер
folders.folderEditWindow.invalidSortOrder=Неверный порядковый номер