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;
private BindingDataSetEventType type;
private String value;
private String oldName;
+ List<BindingData> oldModels = new ArrayList<BindingData>();
public SetDataSourceCommand(BindingDataSetEventType type, AppManager appManager, BindingData bindingData, int index) {
this.type = type;
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);
}
}
}
@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 {
return bindingDataSet.getViewModels();
}
- public void addDataSource(BindingData bindingData) {
- bindingDataSet.addDataSource(bindingData);
+ public void addDataSource(BindingData bindingData, List<BindingData> oldModels) {
+ bindingDataSet.addDataSource(bindingData, oldModels);
}
public void removeDataSource(BindingData bindingData) {
private void setBindingInfos(HtmlMetaFileData fileData) {
List<BindingData> dataSources = fileData.getDataSources();
for (BindingData dataSource : dataSources) {
- getBindingDataSet().addDataSource(dataSource);
+ getBindingDataSet().addDataSource(dataSource, null);
}
List<BindingData> viewModels = fileData.getViewModels();
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;
if ((treeItems == null) || (treeItems.length < 1)) {
return false;
} else {
- return true;
+ if (treeItems[0].getParentItem() == null) {
+ return true;
+ } else {
+ return false;
+ }
}
}
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<String> itemPath = makeItemPath(treeItem);
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);
}
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.
}
}
}
+
+ public Command removeBindingInfo(String name, List<String> 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<String> 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<itemPath.size(); i++) {
+ if (!itemPath.get(itemPath.size()-1-i).equals(modelPath[i])) {
+ return null;
+ }
+ }
+
+ part = (Part) tableItem.getData("PART");
+
+ return part;
+ }
public boolean canRemoveBindingInfo() {
TableItem[] tableItems = infoTableViewer.getTable().getSelection();
@Override
public void dataSourceRenamed(BindingDataSetEvent e) {
- List<BindingData> models = pageDesigner.getAppManager().getViewModels();
- for (BindingData model : models) {
- if (model.getSourceName().equals(e.getOldValue())) {
- model.setSourceName(e.getValue());
+ if (pageDesigner != null) {
+ List<BindingData> models = pageDesigner.getAppManager().getViewModels();
+ for (BindingData model : models) {
+ if (model.getSourceName().equals(e.getOldValue())) {
+ model.setSourceName(e.getValue());
+ }
}
}
*
* @param observableObject
*/
- public void removeViewModelObjects( BindingObject observableObject ) {
+ public void removeViewModelObject( BindingObject observableObject ) {
viewModelObjects.remove( observableObject );
}
*
* @param observableObject
*/
- public void removeDataSourceObjects( BindingObject observableObject ) {
+ public void removeDataSourceObject( BindingObject observableObject ) {
dataSourceObjects.remove( observableObject );
}
public void clearDataSourceObjects() {
dataSourceObjects.clear();
}
+
+ public void removeAllDataSourceObject(List<BindingObject> dataSourceObjects) {
+ for (BindingObject dataSourceObject : dataSourceObjects) {
+ for (BindingObject viewModelObject : viewModelObjects) {
+ if (viewModelObject.getName().equals(dataSourceObject.getName())) {
+ removeViewModelObject(viewModelObject);
+ break;
+ }
+ }
+ }
+ }
/**
* Gets a updateOnStartup info.
}
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;
}
}
* @param bindingData
* a data source
*/
- public void addDataSource(BindingData bindingData) {
+ public void addDataSource(BindingData bindingData, List<BindingData> oldModels) {
dataSources.add(bindingData);
selectionPath.clear();
if (bindingData.getItemName() == null) {
selectionPath.add(bindingData.getItemName());
}
+ if ((oldModels != null) && (!oldModels.isEmpty())) {
+ addDataSourceObjectInModel(oldModels);
+ }
+
fireEvent(new BindingDataSetEvent(BindingDataSetEventType.DATASOURCE_ADDED, bindingData, getNumberOfDataSources() - 1 , null));
}
//
// return null;
// }
-
+
public BindingData getDataSource(String name) {
List<BindingData> DataSources = getDataSources();
for (BindingData DataSource : DataSources) {
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<BindingData> oldModels) {
+ viewModels.clear();
+ viewModels.addAll(oldModels);
+ }
+
public void renameDataSource(BindingDataSetEventType type,
BindingData bindingData, String newName) {
if (type.equals(BindingDataSetEventType.DATASOURCE_RENAMED)) {