From: <mwl...@us...> - 2008-03-05 15:51:44
|
Revision: 644 http://cishell.svn.sourceforge.net/cishell/?rev=644&view=rev Author: mwlinnem Date: 2008-03-05 07:51:41 -0800 (Wed, 05 Mar 2008) Log Message: ----------- Small refactoring. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/AbstractDataManagerView.java Modified: trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/AbstractDataManagerView.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/AbstractDataManagerView.java 2008-03-05 15:34:19 UTC (rev 643) +++ trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/AbstractDataManagerView.java 2008-03-05 15:51:41 UTC (rev 644) @@ -13,7 +13,6 @@ * ***************************************************************************/ package org.cishell.reference.gui.datamanager; -import java.io.IOException; import java.util.Dictionary; import java.util.HashMap; import java.util.HashSet; @@ -217,38 +216,26 @@ viewer.getControl().setFocus(); } - public void dataAdded(final Data data, String label) { - // get the data from the model needed to setup the DataModelGUIItem - Dictionary modelDictionary = data.getMetaData(); - - Data parent = (Data) modelDictionary.get(DataProperty.PARENT); - DataGUIItem parentItem; - if (parent == null) { - // if it has no parent, it is a child of the root - parentItem = rootItem; - } else { - // otherwise find the associated DataModelGUIItem for the parent - parentItem = (DataGUIItem) dataToDataGUIItemMap.get(parent); - - //The parent may not be in the GUI. If its not, then use root item - if (parentItem == null) { - parentItem = rootItem; - } - } - - // create the new DataModelGUIItem - final DataGUIItem item = new DataGUIItem(data, parentItem, + public void dataAdded(final Data newData, String label) { + + //get the new data's parent GUI Item (either root or another data item) + DataGUIItem parentItem = getParent(newData); + + // wrap the new data in a DataGUIItem + final DataGUIItem newItem = new DataGUIItem(newData, parentItem, this.brandPluginID); + // notify the parent DataModelGUIItem of its new child - parentItem.addChild(item); + parentItem.addChild(newItem); + // keep a reference to the new model in the model->TreeItem mapping so // that // it can be used in the future if it has a child - dataToDataGUIItemMap.put(data, item); + dataToDataGUIItemMap.put(newData, newItem); // update the ModelManager with the new selection final Set selection = new HashSet(); - selection.add(data); + selection.add(newData); guiRun(new Runnable() { public void run() { @@ -257,15 +244,36 @@ viewer.refresh(); // context menu may need to have options enabled/disabled // based on the new selection - updateContextMenu(data); + updateContextMenu(newData); // update the global selection - viewer.expandToLevel(item, 0); + viewer.expandToLevel(newItem, 0); manager.setSelectedData((Data[]) selection.toArray(new Data[0])); } } }); } + private DataGUIItem getParent(Data data) { + Dictionary modelDictionary = data.getMetaData(); + + Data parent = (Data) modelDictionary.get(DataProperty.PARENT); + DataGUIItem parentItem; + if (parent == null) { + // if it has no parent, it is a child of the root + parentItem = rootItem; + } else { + // otherwise find the associated DataModelGUIItem for the parent + parentItem = (DataGUIItem) dataToDataGUIItemMap.get(parent); + + //The parent may not be in the GUI. If its not, then use root item + if (parentItem == null) { + parentItem = rootItem; + } + } + + return parentItem; + } + private void guiRun(Runnable run) { if (Thread.currentThread() == Display.getDefault().getThread()) { run.run(); @@ -454,7 +462,6 @@ model.getMetaData().put(DataProperty.LABEL, newLabel); viewer.refresh(); newEditor.dispose(); - updatingTreeItem = false; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |