From 6000b6f2edebfee27cf44dc119cdca3795c0dfb2 Mon Sep 17 00:00:00 2001 From: jaeyeol lee Date: Fri, 28 Mar 2014 17:09:14 +0900 Subject: [PATCH] DATABIND : Set expand & selection in the tree when it refreshed Change-Id: Ie30abf46df9ce5e06eb8ac5f710216fcc897d7e0 Signed-off-by: jaeyeol lee --- .../gef/commands/SetViewModelCommand.java | 6 +- .../tizen/webuibuilder/model/app/AppManager.java | 8 +- .../views/databinding/DataBindingDnDManager.java | 4 - .../ui/views/databinding/DataBindingPage.java | 91 +++++++++++++++++++++- .../ui/views/databinding/model/BindingDataSet.java | 64 ++++++++++++--- 5 files changed, 150 insertions(+), 23 deletions(-) diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/commands/SetViewModelCommand.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/commands/SetViewModelCommand.java index 30cead3..ec828e3 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/commands/SetViewModelCommand.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/commands/SetViewModelCommand.java @@ -59,7 +59,7 @@ public class SetViewModelCommand extends Command { if (type.equals(BindingDataSetEventType.VIEWMODEL_ITEM_ADDED)) { setViewModelItem(type); } else if (type.equals(BindingDataSetEventType.VIEWMODEL_ITEM_REMOVED)) { - oldViewModelObject = getViewModelObject(bindingData, itemPath, childName); + oldViewModelObject = getViewModelObject(bindingData, itemPath); setViewModelItem(type); } else if (type.equals(BindingDataSetEventType.VIEWMODEL_SET_DATASOURCE)) { BindingData data = getViewModel(bindingData.getName()); @@ -79,9 +79,9 @@ public class SetViewModelCommand extends Command { } private BindingObject getViewModelObject(BindingData bindingData, - List itemPath, String childName) { + List itemPath) { - return appManager.getViewModelObject(bindingData, itemPath, childName); + return appManager.getViewModelObject(bindingData, itemPath); } private void setViewModelItem(BindingDataSetEventType type) { 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 5ad3518..be47430 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 @@ -716,6 +716,10 @@ public class AppManager implements IPageDataSetListener, IAppListener { return ProjValidateType.PROJ_OK; } + public List getSelectionPath() { + return bindingDataSet.getSelectionPath(); + } + public BindingDataSet getBindingDataSet() { return bindingDataSet; } @@ -725,8 +729,8 @@ public class AppManager implements IPageDataSetListener, IAppListener { } public BindingObject getViewModelObject(BindingData bindingData, - List itemPath, String childName) { - return bindingDataSet.getViewModelObject(bindingData, itemPath, childName); + List itemPath) { + return bindingDataSet.getViewModelObject(bindingData, itemPath); } public void addViewModel(BindingData bindingData) { diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/databinding/DataBindingDnDManager.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/databinding/DataBindingDnDManager.java index f753ae3..59b13d0 100644 --- a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/databinding/DataBindingDnDManager.java +++ b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/databinding/DataBindingDnDManager.java @@ -254,10 +254,6 @@ public class DataBindingDnDManager { } public void drop(DropTargetEvent event) { - if (event == null) { - return; - } - if (event.data == null) { event.detail = DND.DROP_NONE; return; 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 bbaea7a..07b89c0 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 @@ -115,6 +115,7 @@ public class DataBindingPage extends Page implements IBindingDataSetListener { private Part oldSelectedModel = null; private IAction undoHandler; private IAction redoHandler; + //private List itemPath; public DataBindingPage(DataBindingView dataBindingView) { this.dataBindingView = dataBindingView; @@ -192,10 +193,94 @@ public class DataBindingPage extends Page implements IBindingDataSetListener { refreshViewModelTree(viewModelTree); refreshBindingInfos(); refreshActions(); + + expandTreeItem(); } } - private void refreshActions() { + private void expandTreeItem() { + + if (pageDesigner == null) { + return; + } + + List itemPath = pageDesigner.getAppManager().getSelectionPath(); + if ((itemPath == null) || (itemPath.isEmpty())){ + return; + } + + List modelPath = new ArrayList(); + for (int i=0; i itemPath) { + String itemName = itemPath.get(itemPath.size()-1); + itemPath.remove(itemPath.size()-1); + TreeItem[] treeItems = tree.getItems(); + TreeItem selectedItem = null; + for (TreeItem treeItem : treeItems) { + if (treeItem.getText().equals(itemName)) { + if (itemPath.isEmpty()) { + selectedItem = treeItem; + } else { + selectedItem = getSelectedItem(treeItem, itemPath); + } + break; + } + } + return selectedItem; + } + + private TreeItem getSelectedItem(TreeItem parentTreeItem, List itemPath) { + if (itemPath.isEmpty()) { + return parentTreeItem; + } + String itemName = itemPath.get(itemPath.size()-1); + itemPath.remove(itemPath.size()-1); + + TreeItem[] treeItems = parentTreeItem.getItems(); + TreeItem selectedItem = null; + + for (TreeItem treeItem : treeItems) { + if (treeItem.getText().equals(itemName)) { + selectedItem = getSelectedItem(treeItem, itemPath); + break; + } + } + + return selectedItem; + } + + private void refreshActions() { if (undoHandler != null) { ((UpdateAction) undoHandler).update(); } @@ -459,7 +544,7 @@ public class DataBindingPage extends Page implements IBindingDataSetListener { TreeItem[] selectedItems = viewModelTree.getSelection(); - if (selectedItems.length != 0) { + if (selectedItems.length > 0) { int idIndex = 0; while (!canSetTreeItemName(selectedItems[0], "viewModelItem" + idIndex)) { idIndex++; @@ -715,8 +800,6 @@ public class DataBindingPage extends Page implements IBindingDataSetListener { composite.setLayout(new FillLayout()); SashForm sashForm = new SashForm(composite, SWT.HORIZONTAL); - // viewModelCount = 0; - // dataSourceCount = 0; makeDataModelParentPanel(sashForm); makeBindingInfoPanel(sashForm); 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 51e5e01..61cf92a 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 @@ -35,6 +35,7 @@ public class BindingDataSet { private List viewModels = new ArrayList(); private List dataSources = new ArrayList(); + private List selectionPath = new ArrayList(); private List listeners = new ArrayList(); private List removeListeners = new ArrayList(); @@ -48,7 +49,8 @@ public class BindingDataSet { */ public void addViewModel(BindingData bindingData) { viewModels.add(bindingData); - + selectionPath.clear(); + selectionPath.add(bindingData.getName()); fireEvent(new BindingDataSetEvent(BindingDataSetEventType.VIEWMODEL_ADDED, bindingData, getNumberOfViewModels() - 1 , null)); } @@ -64,11 +66,12 @@ public class BindingDataSet { } public void changeViewModel(BindingDataSetEventType type, BindingData bindingData, List itemPath, String childName, String value) { + selectionPath = itemPath; if (type.equals(BindingDataSetEventType.VIEWMODEL_ITEM_ADDED)) { List viewModels = getViewModels(); for (BindingData viewModel : viewModels) { if (viewModel.equals(bindingData)) { - BindingObject viewModelObject = getViewModelObject(bindingData, itemPath, childName); + BindingObject viewModelObject = getViewModelObject(bindingData, itemPath); if (viewModelObject != null) { addChildViewModelObject(viewModelObject, childName, value); } else if (childName != null) { @@ -81,7 +84,7 @@ public class BindingDataSet { List viewModels = getViewModels(); for (BindingData viewModel : viewModels) { if (viewModel.equals(bindingData)) { - BindingObject viewModelObject = getViewModelParentObject(bindingData, itemPath, childName); + BindingObject viewModelObject = getViewModelParentObject(bindingData, itemPath); if (viewModelObject != null) { removeChildViewModelObject(viewModelObject, childName, value); } else if (childName != null) { @@ -99,11 +102,12 @@ public class BindingDataSet { public void changeViewModel(BindingDataSetEventType type, BindingData bindingData, List itemPath, BindingObject viewModelObject, String value) { + selectionPath = itemPath; if (type.equals(BindingDataSetEventType.VIEWMODEL_ITEM_ADDED)) { List viewModels = getViewModels(); for (BindingData viewModel : viewModels) { if (viewModel.equals(bindingData)) { - BindingObject viewModelParentObject = getViewModelParentObject(bindingData, itemPath, viewModelObject.getName()); + BindingObject viewModelParentObject = getViewModelParentObject(bindingData, itemPath); if (viewModelParentObject != null) { viewModelParentObject.add(viewModelObject); } else { @@ -131,20 +135,21 @@ public class BindingDataSet { private BindingObject getViewModelParentObject(BindingData bindingData, - List itemPath, String childName) { - if ((itemPath == null) || (itemPath.isEmpty())) { + List itemPath) { + if ((itemPath == null) || (itemPath.size() < 2)) { return null; } List modelPath = new ArrayList(); - for (int i=0; i itemPath, String childName) { + List itemPath) { List viewModelObjects = bindingData.getViewModelObjects(); BindingObject object = null; List modelPath = new ArrayList(); @@ -207,6 +212,8 @@ public class BindingDataSet { break; } } + selectionPath.clear(); + selectionPath.add(bindingData.getName()); viewModels.remove(index); fireEvent(new BindingDataSetEvent(BindingDataSetEventType.VIEWMODEL_REMOVED, bindingData, index, null)); } @@ -321,7 +328,8 @@ public class BindingDataSet { */ public void addDataSource(BindingData bindingData) { dataSources.add(bindingData); - + selectionPath.clear(); + selectionPath.add(bindingData.getSourceName()); fireEvent(new BindingDataSetEvent(BindingDataSetEventType.DATASOURCE_ADDED, bindingData, getNumberOfDataSources() - 1 , null)); } @@ -347,6 +355,8 @@ public class BindingDataSet { break; } } + selectionPath.clear(); + selectionPath.add(bindingData.getName()); dataSources.remove(index); fireEvent(new BindingDataSetEvent(BindingDataSetEventType.DATASOURCE_REMOVED, bindingData, index, null)); } @@ -456,4 +466,38 @@ public class BindingDataSet { } } + public List getSelectionPath() { + //if the object does not exist, then select parent object. + if (!isExist(selectionPath)) { + if (selectionPath.size() > 1) { + List modelPath = new ArrayList(); + for (int i=0; i selectionPath) { + if (selectionPath.size() < 1 ) { + return false; + } + BindingData data = getViewModel(selectionPath.get(selectionPath.size()-1)); + if (data != null) { + BindingObject viewModelObject = getViewModelObject(data, selectionPath); + if (viewModelObject == null) { + return false; + } + } else { + data = getDataSource(selectionPath.get(selectionPath.size()-1)); + if (data == null) { + return false; + } + } + return true; + } + } -- 2.7.4