From fa9794643bd8e3dd5a69496bb0601089a1645897 Mon Sep 17 00:00:00 2001 From: jaeyeol lee Date: Wed, 7 May 2014 19:28:06 +0900 Subject: [PATCH] DATABIND : Modify the delete functions in the databinding view If data source is deleted, the model is modified automatically model, widget works similarly Change-Id: I66038bed9cacc8b7ceb6b681deac22597312bb8e Signed-off-by: jaeyeol lee --- .../gef/commands/SetDataSourceCommand.java | 15 ++-- .../tizen/webuibuilder/model/app/AppManager.java | 4 +- .../webuibuilder/model/app/AppManagerForHTML.java | 2 +- .../ui/views/databinding/DataBindingPage.java | 81 ++++++++++++++++++++-- .../ui/views/databinding/model/BindingData.java | 15 +++- .../ui/views/databinding/model/BindingDataSet.java | 27 ++++++-- 6 files changed, 126 insertions(+), 18 deletions(-) diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/commands/SetDataSourceCommand.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/commands/SetDataSourceCommand.java index 53809c1..6457fe8 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/commands/SetDataSourceCommand.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/commands/SetDataSourceCommand.java @@ -1,5 +1,8 @@ package org.tizen.webuibuilder.gef.commands; +import java.util.ArrayList; +import java.util.List; + import org.eclipse.gef.commands.Command; import org.tizen.webuibuilder.model.app.AppManager; import org.tizen.webuibuilder.ui.views.databinding.model.BindingData; @@ -14,6 +17,7 @@ public class SetDataSourceCommand extends Command { private BindingDataSetEventType type; private String value; private String oldName; + List oldModels = new ArrayList(); public SetDataSourceCommand(BindingDataSetEventType type, AppManager appManager, BindingData bindingData, int index) { this.type = type; @@ -43,18 +47,21 @@ public class SetDataSourceCommand extends Command { public void execute() { if (canExecute()) { if (type.equals(BindingDataSetEventType.DATASOURCE_REMOVED)) { + for (BindingData model : appManager.getViewModels()) { + oldModels.add(model.clone()); + } appManager.removeDataSource(bindingData); } else if (type.equals(BindingDataSetEventType.DATASOURCE_CHANGED)) { oldBindingData = appManager.getDataSource(bindingData.getItemName()); if (oldBindingData != null) { appManager.removeDataSource(oldBindingData); } - appManager.addDataSource(bindingData); + appManager.addDataSource(bindingData, null); } else if (type.equals(BindingDataSetEventType.DATASOURCE_RENAMED)) { oldName = bindingData.getSourceName(); renameDataSource(value); } else { - appManager.addDataSource(bindingData); + appManager.addDataSource(bindingData, null); } } } @@ -66,10 +73,10 @@ public class SetDataSourceCommand extends Command { @Override public void undo() { if (type.equals(BindingDataSetEventType.DATASOURCE_REMOVED)) { - appManager.addDataSource(bindingData); + appManager.addDataSource(bindingData, oldModels); } else if (type.equals(BindingDataSetEventType.DATASOURCE_CHANGED)) { appManager.removeDataSource(bindingData); - appManager.addDataSource(oldBindingData); + appManager.addDataSource(oldBindingData, null); } else if (type.equals(BindingDataSetEventType.DATASOURCE_RENAMED)) { renameDataSource(oldName); } else { diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/model/app/AppManager.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/model/app/AppManager.java index c5eee8c..6557eec 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/model/app/AppManager.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/model/app/AppManager.java @@ -769,8 +769,8 @@ public class AppManager implements IPageDataSetListener, IAppListener { return bindingDataSet.getViewModels(); } - public void addDataSource(BindingData bindingData) { - bindingDataSet.addDataSource(bindingData); + public void addDataSource(BindingData bindingData, List oldModels) { + bindingDataSet.addDataSource(bindingData, oldModels); } public void removeDataSource(BindingData bindingData) { diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/model/app/AppManagerForHTML.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/model/app/AppManagerForHTML.java index baf67a7..bf4966c 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/model/app/AppManagerForHTML.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/model/app/AppManagerForHTML.java @@ -233,7 +233,7 @@ public class AppManagerForHTML extends AppManager { private void setBindingInfos(HtmlMetaFileData fileData) { List dataSources = fileData.getDataSources(); for (BindingData dataSource : dataSources) { - getBindingDataSet().addDataSource(dataSource); + getBindingDataSet().addDataSource(dataSource, null); } List viewModels = fileData.getViewModels(); diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/databinding/DataBindingPage.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/databinding/DataBindingPage.java index 52be132..934c1b2 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/databinding/DataBindingPage.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/databinding/DataBindingPage.java @@ -78,6 +78,7 @@ import org.eclipse.ui.part.Page; import org.eclipse.ui.views.contentoutline.ContentOutline; import org.tizen.webuibuilder.BuilderConstants; import org.tizen.webuibuilder.gef.commands.SetDataSourceCommand; +import org.tizen.webuibuilder.gef.commands.SetPartPropertyCommand; import org.tizen.webuibuilder.gef.commands.SetViewModelCommand; import org.tizen.webuibuilder.model.Part; import org.tizen.webuibuilder.model.page.PageData; @@ -648,7 +649,11 @@ public class DataBindingPage extends Page implements IBindingDataSetListener { if ((treeItems == null) || (treeItems.length < 1)) { return false; } else { - return true; + if (treeItems[0].getParentItem() == null) { + return true; + } else { + return false; + } } } @@ -669,9 +674,15 @@ public class DataBindingPage extends Page implements IBindingDataSetListener { if (treeItem.getParentItem() == null) { BindingData bindingData = pageDesigner.getAppManager().getViewModel(treeItem.getText()); + Command command = new SetViewModelCommand(BindingDataSetEventType.VIEWMODEL_REMOVED, pageDesigner.getAppManager(), bindingData, 0); + + Command removeCommand = removeBindingInfo(treeItem.getText(), null); + if (removeCommand != null) { + command = command.chain(removeCommand); + } getCommandStackFromPageDesigner().execute(command); } else { List itemPath = makeItemPath(treeItem); @@ -682,6 +693,10 @@ public class DataBindingPage extends Page implements IBindingDataSetListener { new SetViewModelCommand(BindingDataSetEventType.VIEWMODEL_ITEM_REMOVED, pageDesigner.getAppManager(), bindingData, itemPath, treeItem.getText(), "", 0); + Command removeCommand = removeBindingInfo(treeItem.getText(), itemPath); + if (removeCommand != null) { + command = command.chain(removeCommand); + } getCommandStackFromPageDesigner().execute(command); } @@ -779,6 +794,11 @@ public class DataBindingPage extends Page implements IBindingDataSetListener { delegater.valueChanged(part, BuilderConstants.ATTRIBUTE_DATA_BIND, "", true); } } + + public Command createRemovePropertyCommand(Part part) { + Command command = new SetPartPropertyCommand(part, BuilderConstants.ATTRIBUTE_DATA_BIND, "", true); + return command; + } /** * Gets the view model tree. @@ -896,6 +916,55 @@ public class DataBindingPage extends Page implements IBindingDataSetListener { } } } + + public Command removeBindingInfo(String name, List itemPath) { + Command command = null; + TableItem[] tableItems = infoTableViewer.getTable().getItems(); + for (TableItem tableItem : tableItems) { + String[] modelPath = tableItem.getText().split("\\."); + if ((modelPath != null)&&(modelPath.length > 0)) { + Part part = null; + if (modelPath[0].equals(name)) { + part = (Part) tableItem.getData("PART"); + } else { + part = getPartFromInfoTabel(tableItem, modelPath, itemPath); + } + if (part != null) { + if (command == null) { + command = createRemovePropertyCommand(part); + } else { + command = command.chain(createRemovePropertyCommand(part)); + } + } + } + } + return command; + } + + private Part getPartFromInfoTabel(TableItem tableItem, String[] modelPath, List itemPath) { + Part part = null; + if ((itemPath == null) || (itemPath.isEmpty())) { + return null; + } + + if (modelPath.length == 0) { + return null; + } + + if (modelPath.length < itemPath.size()) { + return null; + } + + for (int i=0; i models = pageDesigner.getAppManager().getViewModels(); - for (BindingData model : models) { - if (model.getSourceName().equals(e.getOldValue())) { - model.setSourceName(e.getValue()); + if (pageDesigner != null) { + List models = pageDesigner.getAppManager().getViewModels(); + for (BindingData model : models) { + if (model.getSourceName().equals(e.getOldValue())) { + model.setSourceName(e.getValue()); + } } } diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/databinding/model/BindingData.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/databinding/model/BindingData.java index 619deb2..5593776 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/databinding/model/BindingData.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/databinding/model/BindingData.java @@ -451,7 +451,7 @@ public class BindingData { * * @param observableObject */ - public void removeViewModelObjects( BindingObject observableObject ) { + public void removeViewModelObject( BindingObject observableObject ) { viewModelObjects.remove( observableObject ); } @@ -553,7 +553,7 @@ public class BindingData { * * @param observableObject */ - public void removeDataSourceObjects( BindingObject observableObject ) { + public void removeDataSourceObject( BindingObject observableObject ) { dataSourceObjects.remove( observableObject ); } @@ -563,6 +563,17 @@ public class BindingData { public void clearDataSourceObjects() { dataSourceObjects.clear(); } + + public void removeAllDataSourceObject(List dataSourceObjects) { + for (BindingObject dataSourceObject : dataSourceObjects) { + for (BindingObject viewModelObject : viewModelObjects) { + if (viewModelObject.getName().equals(dataSourceObject.getName())) { + removeViewModelObject(viewModelObject); + break; + } + } + } + } /** * Gets a updateOnStartup info. diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/databinding/model/BindingDataSet.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/databinding/model/BindingDataSet.java index a7a2ad2..e1f73e7 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/databinding/model/BindingDataSet.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/databinding/model/BindingDataSet.java @@ -312,14 +312,14 @@ public class BindingDataSet { } if (viewModelObject.getItems().isEmpty()) { - viewModelObject.setType(null); + viewModelObject.setType("String"); } } private void removeChildViewModelObject(BindingData bindingData, String childName, String value) { for (BindingObject object : bindingData.getViewModelObjects()) { if (object.getName().equals(childName)) { - bindingData.removeViewModelObjects(object); + bindingData.removeViewModelObject(object); break; } } @@ -356,7 +356,7 @@ public class BindingDataSet { * @param bindingData * a data source */ - public void addDataSource(BindingData bindingData) { + public void addDataSource(BindingData bindingData, List oldModels) { dataSources.add(bindingData); selectionPath.clear(); if (bindingData.getItemName() == null) { @@ -365,6 +365,10 @@ public class BindingDataSet { selectionPath.add(bindingData.getItemName()); } + if ((oldModels != null) && (!oldModels.isEmpty())) { + addDataSourceObjectInModel(oldModels); + } + fireEvent(new BindingDataSetEvent(BindingDataSetEventType.DATASOURCE_ADDED, bindingData, getNumberOfDataSources() - 1 , null)); } @@ -378,7 +382,7 @@ public class BindingDataSet { // // return null; // } - + public BindingData getDataSource(String name) { List DataSources = getDataSources(); for (BindingData DataSource : DataSources) { @@ -408,11 +412,26 @@ public class BindingDataSet { selectionPath.add(bindingData.getItemName()); } + removeDataSourceObjectInModel(bindingData); dataSources.remove(index); fireEvent(new BindingDataSetEvent(BindingDataSetEventType.DATASOURCE_REMOVED, bindingData, index, null)); } } + private void removeDataSourceObjectInModel(BindingData bindingData) { + for (BindingData model : viewModels) { + if ((model.getSourceName() != null) && (model.getSourceName().equals(bindingData.getSourceName()))) { + model.removeAllDataSourceObject(bindingData.getDataSourceObjects()); + model.setSourceName(null); + } + } + } + + private void addDataSourceObjectInModel(List oldModels) { + viewModels.clear(); + viewModels.addAll(oldModels); + } + public void renameDataSource(BindingDataSetEventType type, BindingData bindingData, String newName) { if (type.equals(BindingDataSetEventType.DATASOURCE_RENAMED)) { -- 2.7.4