From: <bea...@us...> - 2006-09-19 14:02:42
|
Revision: 201 http://svn.sourceforge.net/cishell/?rev=201&view=rev Author: bearsfan Date: 2006-09-19 07:02:36 -0700 (Tue, 19 Sep 2006) Log Message: ----------- Direct conversion of the previous version of the data manager viewer required some external helper classes. Added Paths: ----------- trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/DataGUIItem.java trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/DataTreeContentProvider.java trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/DataTreeLabelProvider.java Added: trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/DataGUIItem.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/DataGUIItem.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/DataGUIItem.java 2006-09-19 14:02:36 UTC (rev 201) @@ -0,0 +1,145 @@ +/* + * InfoVis CyberInfrastructure: A Data-Code-Compute Resource for Research + * and Education in Information Visualization (http://iv.slis.indiana.edu/). + * + * Created on Feb 19, 2005 at Indiana University. + */ +package org.cishell.reference.gui.datamanager; + +import java.io.File; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.cishell.framework.data.Data; +import org.cishell.framework.data.DataProperty; +import org.eclipse.core.runtime.Platform; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.plugin.AbstractUIPlugin; + + +/** + * DataModelGUIItem is a wrapper of a DataModel which is used by the + * DataModelTreeView to hold the items in the TreeView. It adds to the + * DataModel the notion of having parent and children DataModelTreeItems + * and keeps track of this information for usage by the TreeView. + * + * @author Team IVC + */ +public class DataGUIItem { + + private String brandPluginID; + + //images for the defined types + private Image matrixIcon; + private Image treeIcon; + private Image networkIcon; + private Image unknownIcon; + + private Map typeToImageMapping; + + private List children; + private Data data; + private DataGUIItem parent; + + + /** + * Creates a new DataModelGUIItem object. + * + * @param model the DataModel this DataModelGUIItem is using + * @param parent the parent DataModelGUIItem of this DataModelGUIItem + */ + public DataGUIItem(Data data, DataGUIItem parent, String brandPluginID) { + this.data = data; + this.parent = parent; + children = new ArrayList(); + + this.brandPluginID = brandPluginID; + matrixIcon = createImage("table.png", this.brandPluginID); + treeIcon = createImage("tree.png", this.brandPluginID); + networkIcon = createImage("network.png", this.brandPluginID); + unknownIcon = createImage("unknown.png", this.brandPluginID); + + typeToImageMapping = new HashMap(); + registerImage(DataProperty.OTHER_TYPE, unknownIcon); + registerImage(DataProperty.MATRIX_TYPE, matrixIcon); + registerImage(DataProperty.NETWORK_TYPE, networkIcon); + registerImage(DataProperty.TREE_TYPE, treeIcon); + } + + /** + * Returns the DataModel used by this DataModelGUIItem + * + * @return the DataModel used by this DataModelGUIItem + */ + public Data getModel() { + return data; + } + + /** + * Returns the parent DataModelGUIItem of this DataModelGUIItem, or + * null if this is the root item. + * + * @return the parent DataModelGUIItem of this DataModelGUIItem, or + * null if this is the root item + */ + public DataGUIItem getParent() { + return parent; + } + + /** + * Adds the given DataModelGUIItem as a child of this DataModelGUIItem + * + * @param item the new child of this DataModelGUIItem + */ + public void addChild(DataGUIItem item) { + children.add(item); + } + + /** + * Returns an array of all of the children of this DataModelGUIItem + * + * @return an array of all of the children of this DataModelGUIItem + */ + public Object[] getChildren() { + return children.toArray(); + } + + /** + * Removes the given DataModelGUIItem from the collection of children + * of this DataModelGUIItem. + * + * @param item the child of this DataModelGUIItem to remove + */ + public void removeChild(DataGUIItem item) { + children.remove(item); + } + + /** + * Returns the icon associated with this DataModel for display in IVC. + * + * @return the icon associated with this DataModel for display in IVC + */ + public Image getIcon(){ + Image icon = (Image)typeToImageMapping.get(data.getMetaData().get(DataProperty.TYPE)); + if(icon == null) icon = unknownIcon; + return icon; + } + + public void registerImage(String type, Image image){ + typeToImageMapping.put(type, image); + } + + public static Image createImage(String name, String brandPluginID){ + if(Platform.isRunning()){ + return AbstractUIPlugin. + imageDescriptorFromPlugin(brandPluginID, + File.separator + "icons" + File.separator + name). + createImage(); + } + else { + return null; + } + } +} Added: trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/DataTreeContentProvider.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/DataTreeContentProvider.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/DataTreeContentProvider.java 2006-09-19 14:02:36 UTC (rev 201) @@ -0,0 +1,95 @@ +/* + * InfoVis CyberInfrastructure: A Data-Code-Compute Resource for Research + * and Education in Information Visualization (http://iv.slis.indiana.edu/). + * + * Created on Feb 19, 2005 at Indiana University. + */ +package org.cishell.reference.gui.datamanager; + +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.Viewer; + + +/** + * ContentProvider for the DataModel TreeView. This class is used to form + * the structure of the tree that is displayed based on the relationships between + * the DataModelTreeItems within it. + * + * @author Team IVC + */ +public class DataTreeContentProvider implements ITreeContentProvider { + private static final Object[] EMPTY_ARRAY = new Object[0]; + + /** + * Returns the children of the given TreeView element. This parentElement + * should be a DataModelGUIItem + * + * @param parentElement the TreeView element to find the children of + * + * @return Returns the children of the given TreeView element + */ + public Object[] getChildren(Object parentElement) { + if (parentElement instanceof DataGUIItem) { + return ((DataGUIItem) parentElement).getChildren(); + } + + return EMPTY_ARRAY; + } + + /** + * Gets the parent of the given TreeView element. This element should be + * a DataModelGUIItem + * + * @param element the element to find the parent of + * + * @return the parent of the given TreeView element + */ + public Object getParent(Object element) { + if (element instanceof DataGUIItem) { + return ((DataGUIItem) element).getParent(); + } + + return null; + } + + /** + * Determines whether or not the given TreeView element has any children. + * + * @param element the TreeView element to find the children for. + * + * @return true if the given element has children, false if not. + */ + public boolean hasChildren(Object element) { + return getChildren(element).length > 0; + } + + /** + * Returns an array of the elements to display in the TreeViewer + * + * @param inputElement the root element of the TreeViewer + * + * @return an array of the elements to display in the TreeViewer + */ + public Object[] getElements(Object inputElement) { + return getChildren(inputElement); + } + + /** + * Does nothing. + */ + public void dispose() {} + + /** + * Does nothing. + * + * This method could be used to notify this content provider that + * the given viewer's input has been switched to a different element. + * + * @param viewer the viewer + * @param oldInput the old input element, or <code>null</code> if the viewer + * did not previously have an input + * @param newInput the new input element, or <code>null</code> if the viewer + * does not have an input + */ + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} +} Added: trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/DataTreeLabelProvider.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/DataTreeLabelProvider.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/DataTreeLabelProvider.java 2006-09-19 14:02:36 UTC (rev 201) @@ -0,0 +1,63 @@ +/* + * InfoVis CyberInfrastructure: A Data-Code-Compute Resource for Research + * and Education in Information Visualization (http://iv.slis.indiana.edu/). + * + * Created on Feb 19, 2005 at Indiana University. + */ +package org.cishell.reference.gui.datamanager; + +import org.cishell.framework.data.Data; +import org.cishell.framework.data.DataProperty; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.swt.graphics.Image; + + +/** + * LabelProvider for the DataModelTreeView used to represent DataModels in IVC. + * + * @author Team IVC + */ +public class DataTreeLabelProvider extends LabelProvider { + + /** + * Returns the Image associated with the given element that should be + * displayed in the Tree. + * + * @param element the element in the DataModelTreeView for which to + * return the associated Image. + * + * @return the Image associated with the given element that should be + * displayed in the Tree + */ + public Image getImage(Object element) { + if (element instanceof DataGUIItem) { + return ((DataGUIItem) element).getIcon(); + } + + return null; + } + + /** + * Returns the text to display for the given DataModelTreeView element. This + * is the label of the DataModel which the element represents. + * + * @param element the element in the DataModelTreeView to find the text + * to display. + * + * @return the text to display for the given DataModelTreeView element + */ + public String getText(Object element) { + if (element instanceof DataGUIItem) { + Data model = ((DataGUIItem) element).getModel(); + String label = (String) model.getMetaData().get(DataProperty.LABEL); + Boolean modified = (Boolean)model.getMetaData().get(DataProperty.MODIFIED); + if(modified != null && modified.booleanValue()){ + label = ">" + label; + } + + return label; + } + + return null; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |