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. |
From: <bea...@us...> - 2006-10-17 15:42:54
|
Revision: 293 http://svn.sourceforge.net/cishell/?rev=293&view=rev Author: bearsfan Date: 2006-10-17 08:40:07 -0700 (Tue, 17 Oct 2006) Log Message: ----------- Check to see if a BundleContext is around to get a datamanager Modified Paths: -------------- 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/Activator.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 2006-10-16 21:59:06 UTC (rev 292) +++ trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/AbstractDataManagerView.java 2006-10-17 15:40:07 UTC (rev 293) @@ -58,6 +58,8 @@ import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.TreeItem; import org.eclipse.ui.part.ViewPart; +import org.osgi.framework.BundleEvent; +import org.osgi.framework.BundleListener; import org.osgi.service.log.LogService; /** @@ -65,7 +67,7 @@ * @author Bruce Herr (bh...@bh...) */ public abstract class AbstractDataManagerView extends ViewPart implements - DataManagerListener { + DataManagerListener, BundleListener { private String brandPluginID; private DataManagerService manager; @@ -165,11 +167,27 @@ tree.addMouseListener(editorListener); tree.addKeyListener(editorListener); - // listen to IVC for models being added by plugins - manager.addDataManagerListener(this); + // listen to OSGi for models being added by plugins + if (manager != null) { + manager.addDataManagerListener(this); + } + else { + Activator.getBundleContext().addBundleListener(this); + manager = Activator.getDataManagerService(); + if (manager != null) { + manager.addDataManagerListener(this); + } + } getSite().setSelectionProvider(new DataModelSelectionProvider()); } + + public void bundleChanged(BundleEvent event) { + if (event.getType() == BundleEvent.STARTED) { + manager = Activator.getDataManagerService(); + manager.addDataManagerListener(this); + } + } /** * @see org.eclipse.ui.part.WorkbenchPart#setFocus() Modified: trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/Activator.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/Activator.java 2006-10-16 21:59:06 UTC (rev 292) +++ trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/Activator.java 2006-10-17 15:40:07 UTC (rev 293) @@ -36,7 +36,7 @@ */ public void start(BundleContext context) throws Exception { super.start(context); - + Activator.context = context; } @@ -59,9 +59,14 @@ } protected static DataManagerService getDataManagerService() { - DataManagerService manager = (DataManagerService) context.getService( - context.getServiceReference(DataManagerService.class.getName())); + ServiceReference serviceReference = context.getServiceReference(DataManagerService.class.getName()); + DataManagerService manager = null; + if (serviceReference != null) { + manager = (DataManagerService) context.getService(serviceReference); + + } + return manager; } @@ -87,6 +92,10 @@ return null; } } + + protected static BundleContext getBundleContext() { + return context; + } protected static CIShellContext getCIShellContext() { return new LocalCIShellContext(context); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <bea...@us...> - 2006-10-17 19:26:52
|
Revision: 296 http://svn.sourceforge.net/cishell/?rev=296&view=rev Author: bearsfan Date: 2006-10-17 12:26:48 -0700 (Tue, 17 Oct 2006) Log Message: ----------- Added support for viewing and saving from within the DataManager viewer Modified Paths: -------------- 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/Activator.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 2006-10-17 17:04:38 UTC (rev 295) +++ trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/AbstractDataManagerView.java 2006-10-17 19:26:48 UTC (rev 296) @@ -91,10 +91,12 @@ private Map dataToDataGUIItemMap; private AlgorithmFactory saveFactory; + private AlgorithmFactory viewFactory; private DiscardListener discardListener; private SaveListener saveListener; + private ViewListener viewListener; public AbstractDataManagerView(String brandPluginID) { manager = Activator.getDataManagerService(); @@ -102,8 +104,10 @@ dataToDataGUIItemMap = new HashMap(); if (manager == null) { - Activator.getLogService().log(LogService.LOG_ERROR, - "Data Manager Service unavailable!"); + LogService log = Activator.getLogService(); + if (log != null) { + log.log(LogService.LOG_ERROR, "Data Manager Service unavailable!"); + } } } @@ -133,15 +137,14 @@ MenuItem saveItem = new MenuItem(menu, SWT.PUSH); saveItem.setText("Save"); - this.saveFactory = Activator.getSaveService(); - if (this.saveFactory != null) { - saveListener = new SaveListener(); - saveItem.addListener(SWT.Selection, saveListener); - } - else { - saveItem.setEnabled(false); - } + saveListener = new SaveListener(); + saveItem.addListener(SWT.Selection, saveListener); + MenuItem viewItem = new MenuItem(menu, SWT.PUSH); + viewItem.setText("View"); + viewListener = new ViewListener(); + viewItem.addListener(SWT.Selection, viewListener); + MenuItem renameItem = new MenuItem(menu, SWT.PUSH); renameItem.setText("Rename"); renameItem.addListener(SWT.Selection, new Listener() { @@ -185,7 +188,9 @@ public void bundleChanged(BundleEvent event) { if (event.getType() == BundleEvent.STARTED) { manager = Activator.getDataManagerService(); - manager.addDataManagerListener(this); + if (manager != null) { + manager.addDataManagerListener(this); + } } } @@ -303,14 +308,38 @@ * their is an available Persister for the given model */ private void updateContextMenu(Data model) { - // reset the enablement of the save context menu appropriately - // boolean saveEnabled = (model.getData() != null) && - // !(IVC.getInstance().getPersistenceRegistry() - // .getSupportingPersisters(model.getData()).isEmpty()); - boolean saveEnabled = false; - menu.getItem(0).setEnabled(saveEnabled); + saveFactory = enableMenuItemCheck(saveFactory, + "org.cishell.reference.gui.persistence.save.Save", model, 0); + viewFactory = enableMenuItemCheck(viewFactory, + "org.cishell.reference.gui.persistence.view.FileView", model, 1); } + + private AlgorithmFactory enableMenuItemCheck( + AlgorithmFactory algorithmFactory, String service, Data model, + int menuNdx) { + boolean validSaveFactory = false; + if (algorithmFactory == null) { + algorithmFactory = Activator.getService(service); + if (algorithmFactory != null) { + validSaveFactory = true; + } + } else { + validSaveFactory = true; + } + boolean enabled = false; + if (validSaveFactory) { + Algorithm algorithm = algorithmFactory.createAlgorithm( + new Data[] { model }, new Hashtable(), Activator + .getCIShellContext()); + if (algorithm != null) { + enabled = true; + } + } + menu.getItem(menuNdx).setEnabled(enabled); + return algorithmFactory; + } + /* * Listens for selection in the GUI of data models by selecting their item * in the tree and updates the ModelManager appropriately @@ -445,17 +474,30 @@ private class SaveListener implements Listener { public void handleEvent(Event event) { - if (AbstractDataManagerView.this.saveFactory != null) { - TreeItem[] selection = AbstractDataManagerView.this.tree.getSelection(); - Data data = ((DataGUIItem)selection[0].getData()).getModel(); - Algorithm algorithm = AbstractDataManagerView.this.saveFactory.createAlgorithm(new Data[]{data}, - new Hashtable(), - Activator.getCIShellContext()); + if (saveFactory != null) { + Data data[] = AbstractDataManagerView.this.manager + .getSelectedData(); + Algorithm algorithm = saveFactory + .createAlgorithm(data, new Hashtable(), Activator + .getCIShellContext()); algorithm.execute(); } } } + private class ViewListener implements Listener { + public void handleEvent(Event event) { + if (viewFactory != null) { + Data data[] = AbstractDataManagerView.this.manager + .getSelectedData(); + Algorithm algorithm = viewFactory + .createAlgorithm(data, new Hashtable(), Activator + .getCIShellContext()); + algorithm.execute(); + } + } + } + private class DiscardListener implements Listener { public void handleEvent(Event event) { TreeItem[] selection = AbstractDataManagerView.this.tree Modified: trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/Activator.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/Activator.java 2006-10-17 17:04:38 UTC (rev 295) +++ trunk/clients/gui/org.cishell.reference.gui.datamanager/src/org/cishell/reference/gui/datamanager/Activator.java 2006-10-17 19:26:48 UTC (rev 296) @@ -71,17 +71,23 @@ } protected static LogService getLogService() { - LogService log = (LogService) context.getService( + ServiceReference serviceReference = context.getServiceReference(DataManagerService.class.getName()); + LogService log = null; + + if (serviceReference != null) { + log = (LogService) context.getService( context.getServiceReference(LogService.class.getName())); + } return log; } - protected static AlgorithmFactory getSaveService() { + protected static AlgorithmFactory getService(String service) { ServiceReference[] refs; try { refs = context.getServiceReferences(AlgorithmFactory.class.getName(), - "(&("+Constants.SERVICE_PID+"=org.cishell.reference.gui.persistence.save.Save))"); + "(&("+Constants.SERVICE_PID+"="+service+"))"); + //"(&("+Constants.SERVICE_PID+"=org.cishell.reference.gui.persistence.save.Save))"); if (refs != null && refs.length > 0) { return (AlgorithmFactory) context.getService(refs[0]); } else { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |