DatabaseState.java

Go to the documentation of this file.
00001 package edu.rice.cs.hpc.viewer.provider;
00002 
00003 import java.util.HashMap;
00004 import java.util.Map;
00005 
00006 import org.eclipse.ui.AbstractSourceProvider;
00007 import org.eclipse.ui.ISources;
00008 import org.eclipse.ui.IWorkbenchWindow;
00009 import edu.rice.cs.hpc.viewer.window.ViewerWindow;
00010 import edu.rice.cs.hpc.viewer.window.ViewerWindowManager;
00011 
00012 public class DatabaseState extends AbstractSourceProvider 
00013 {
00014     public final static String DATABASE_ACTIVE_STATE = "edu.rice.cs.hpc.viewer.provider.data.active";
00015     public final static String DATABASE_MERGE_STATE  = "edu.rice.cs.hpc.viewer.provider.data.merge";
00016     static final public String DATABASE_NEED_REFRESH = "edu.rice.cs.hpc.viewer.provider.data.refresh";
00017 
00018     public final static String ENABLED = "ENABLED";
00019     public final static String DISABLED = "DISABLED";
00020     
00021     private int num_opened_database = 0;
00022     
00023     public void dispose() {
00024     }
00025 
00026     /*
00027      * (non-Javadoc)
00028      * @see org.eclipse.ui.ISourceProvider#getCurrentState()
00029      */
00030     public Map getCurrentState() 
00031     {
00032         Map<String, Object> map = new HashMap<String, Object>(2);
00033         String value = num_opened_database>0 ? ENABLED : DISABLED;
00034         map.put(DATABASE_ACTIVE_STATE, value);
00035         
00036         value = num_opened_database>1 ? ENABLED : DISABLED;
00037         map.put(DATABASE_MERGE_STATE, value);
00038         
00039         map.put(DATABASE_NEED_REFRESH, Boolean.valueOf(false));
00040         
00041         return map;
00042     }
00043 
00044     /*
00045      * (non-Javadoc)
00046      * @see org.eclipse.ui.ISourceProvider#getProvidedSourceNames()
00047      */
00048     public String[] getProvidedSourceNames() 
00049     {
00050         return new String[] { DATABASE_ACTIVE_STATE, DATABASE_MERGE_STATE, DATABASE_NEED_REFRESH };
00051     }
00052 
00053 
00054     public void toogleEnabled(IWorkbenchWindow window) 
00055     {
00056         ViewerWindow vw = ViewerWindowManager.getViewerWindow(window);
00057         
00058         num_opened_database = vw.getOpenDatabases();
00059         String value = num_opened_database>0 ? ENABLED : DISABLED;
00060         fireSourceChanged(ISources.WORKBENCH, DATABASE_ACTIVE_STATE, value);
00061         
00062         value = num_opened_database>1 ? ENABLED : DISABLED;
00063         fireSourceChanged(ISources.WORKBENCH, DATABASE_MERGE_STATE, value);
00064     }
00065 
00066     public void refreshDatabase(boolean filter)
00067     {
00068         fireSourceChanged(ISources.WORKBENCH, DATABASE_NEED_REFRESH, filter);
00069     }
00070 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1