// The event handler called when you choose the options between: // to see folder size information or file type size information private void comboAction_SelectedIndexChanged(object sender, EventArgs e) { if (treeView.SelectedNode != null) { switch (comboActionStrategy.SelectedIndex) { case 0: explorer = folderStrategy; break; case 1: explorer = fileTypeStrategy; break; } // Do exploration using selected exploration strategy explorer.analyze(GetAbsolutePath(treeView.SelectedNode)); // Make sure that the display is visible comboObserver_SelectedIndexChanged(null, null); // Display status labelStatus.Text = "Result of path " + GetAbsolutePath(treeView.SelectedNode); } }
public StorageExplorerForm() { InitializeComponent(); // Initialize the tree view InitTreeView(); // Create the strategy subjects folderStrategy = new DirectoryStrategy(); fileTypeStrategy = new FileExtensionStrategy(); explorer = folderStrategy; //fileTypeStrategy is default strategy // Create the display ConcreteObservers folderList = new FolderListView(); fileTypeList = new FileTypeListView(); //Create the visualization strategy pieChart = new PieGraphAdapter(); barChart = new BarGraphAdapter(); // Subscribe ConcreteObserver objects to ExploringStrategy objects // so when the explorer finish its exploration it // will notify all the subscribers. folderList.SubscribeToDescoverEvent(folderStrategy); fileTypeList.SubscribeToDescoverEvent(fileTypeStrategy); pieChart.SubscribeToDescoverEvent(folderStrategy); pieChart.SubscribeToDescoverEvent(fileTypeStrategy); barChart.SubscribeToDescoverEvent(folderStrategy); barChart.SubscribeToDescoverEvent(fileTypeStrategy); // Select the first option in dropdown comboActionStrategy.SelectedIndex = 0; visualizationCombo.SelectedIndex = 1; pieChart.AddToContainer(rightPanel); this.visualizationCombo.SelectedIndexChanged += new EventHandler(this.comboObserver_SelectedIndexChanged); this.comboActionStrategy.SelectedIndexChanged += new EventHandler(this.comboAction_SelectedIndexChanged); this.treeView.AfterSelect += new TreeViewEventHandler(this.treeView_AfterSelect); this.treeView.BeforeExpand += new TreeViewCancelEventHandler(this.treeView_BeforeExpand); //calculate DescoverProgressEventHandler for both of strategies folderStrategy.OnProgess += new DescoverProgressEventHandler(DisplayProgress); fileTypeStrategy.OnProgess += new DescoverProgressEventHandler(DisplayProgress); }
/// <summary> /// This method is used for delegating observer update method which is belons to this class's update method /// by DescoverStrategy Finished event. /// </summary> /// <param name="obj"></param> public void SubscribeToDescoverEvent(DescoverStrategy obj) { obj.Finished += UpdateDraw; }