TreeItemManager.java

Go to the documentation of this file.
00001 
00004 package edu.rice.cs.hpc.viewer.util;
00005 
00006 import java.util.Stack;
00007 
00008 import org.eclipse.jface.viewers.TreeViewer;
00009 import org.eclipse.swt.graphics.Image;
00010 import org.eclipse.swt.widgets.Tree;
00011 import org.eclipse.swt.widgets.TreeItem;
00012 
00013 import edu.rice.cs.hpc.data.experiment.scope.Scope;
00014 
00019 public class TreeItemManager {
00020 
00021     private Stack<ElementDescriptor> stackElement;
00022     
00026     public TreeItemManager() {
00027         this.stackElement = new Stack<ElementDescriptor>();
00028     }
00029     
00034     public void saveContext(TreeViewer treeViewer) {
00035         final Tree tree = treeViewer.getTree();
00036         if (!tree.isDisposed())
00037         {
00038             ElementDescriptor objDesc = this.getTopItem(tree);
00039             if (objDesc != null)
00040                 this.stackElement.push(objDesc);
00041         }
00042     }
00043     
00048     public void restoreContext(TreeViewer treeViewer) {
00049         if (this.stackElement.size()>0) {
00050             ElementDescriptor objDesc = this.stackElement.pop();
00051             Tree tree = treeViewer.getTree();
00052             if (!tree.isDisposed())
00053             {
00054                 Utilities.insertTopRow(treeViewer, objDesc.imgElement, objDesc.sTextElement);
00055             }
00056         }
00057     }
00058     
00064     private ElementDescriptor getTopItem(Tree tree) {
00065         if (tree.getItemCount() == 0)
00066             return null;
00067         
00068         TreeItem itemTop = tree.getItem(0);
00069         Image imgItem = itemTop.getImage(0);
00070         String []sText= null;
00071         if(itemTop.getData() instanceof Scope) {
00072             // the table has been zoomed-out
00073         } else {
00074             // the table is in original form or flattened or zoom-in
00075             Object o = itemTop.getData();
00076             if(o != null) {
00077                 Object []arrObj = (Object []) o;
00078                 if(arrObj[0] instanceof String) {
00079                     sText = (String[]) itemTop.getData(); 
00080                 }
00081             }
00082         }
00083         return new ElementDescriptor(itemTop, imgItem, sText);
00084     }
00085 
00091     private class ElementDescriptor {
00092         Image imgElement;
00093         String []sTextElement;
00094         
00095         
00102         ElementDescriptor (TreeItem item, Image img, String []sTexts) {
00103             this.imgElement = img;
00104             this.sTextElement = sTexts;
00105         }
00106     }
00107 
00108 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1