- Timestamp:
- 05/05/10 10:38:19 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.PluginInfrastructure/Advanced/ProductEditor.cs
r3612 r3624 114 114 "There was an error while connecting to the server." + Environment.NewLine + 115 115 "Please check your connection settings and user credentials."); 116 DisableControls(); 116 this.products.Clear(); 117 this.plugins.Clear(); 117 118 } else { 118 119 this.products = new List<DeploymentService.ProductDescription>( … … 121 122 (DeploymentService.PluginDescription[])((object[])e.Result)[1]); 122 123 123 UpdateProductsList();124 dirtyProducts.Clear();125 124 EnableControls(); 126 125 } 126 UpdateProductsList(); 127 dirtyProducts.Clear(); 127 128 StatusView.HideProgressIndicator(); 128 129 StatusView.RemoveMessage(DeleteProductMessage); … … 179 180 "There was an error while connecting to the server." + Environment.NewLine + 180 181 "Please check your connection settings and user credentials."); 181 DisableControls(); 182 this.products.Clear(); 183 this.plugins.Clear(); 182 184 } else { 183 185 this.products = new List<DeploymentService.ProductDescription>( … … 186 188 (DeploymentService.PluginDescription[])((object[])e.Result)[1]); 187 189 188 UpdateProductsList();189 dirtyProducts.Clear();190 EnableControls();191 }190 } 191 UpdateProductsList(); 192 dirtyProducts.Clear(); 193 EnableControls(); 192 194 StatusView.HideProgressIndicator(); 193 195 StatusView.RemoveMessage(UploadMessage); … … 222 224 "There was an error while connecting to the server." + Environment.NewLine + 223 225 "Please check your connection settings and user credentials."); 224 DisableControls(); 226 this.products.Clear(); 227 this.plugins.Clear(); 228 225 229 } else { 226 230 this.products = new List<DeploymentService.ProductDescription>( … … 228 232 this.plugins = new List<DeploymentService.PluginDescription>( 229 233 (DeploymentService.PluginDescription[])((object[])e.Result)[1]); 230 231 232 UpdateProductsList(); 233 dirtyProducts.Clear(); 234 EnableControls(); 235 } 234 } 235 UpdateProductsList(); 236 dirtyProducts.Clear(); 237 EnableControls(); 236 238 StatusView.HideProgressIndicator(); 237 239 StatusView.RemoveMessage(RefreshMessage); … … 241 243 242 244 private void UpdateProductsList() { 245 productsListView.SelectedItems.Clear(); 243 246 productsListView.Items.Clear(); 244 247 foreach (var prodDesc in products) { 245 248 productsListView.Items.Add(CreateListViewItem(prodDesc)); 246 249 } 247 foreach (ColumnHeader column in productsListView.Columns) 248 if (productsListView.Items.Count > 0) 249 column.AutoResize(ColumnHeaderAutoResizeStyle.ColumnContent); 250 else column.AutoResize(ColumnHeaderAutoResizeStyle.HeaderSize); 250 Util.ResizeColumns(productsListView.Columns.OfType<ColumnHeader>()); 251 251 } 252 252 … … 254 254 bool productSelected = productsListView.SelectedItems.Count > 0; 255 255 detailsGroupBox.Enabled = productSelected; 256 deleteProductButton.Enabled = productSelected; 257 uploadButton.Enabled = dirtyProducts.Count > 0; 256 UpdateProductButtons(); 258 257 if (productSelected) { 259 258 DeploymentService.ProductDescription activeProduct = (DeploymentService.ProductDescription)((ListViewItem)productsListView.SelectedItems[0]).Tag; … … 263 262 // populate plugins list view 264 263 ListViewItem activeItem = (ListViewItem)productsListView.SelectedItems[0]; 264 pluginListView.SuppressItemCheckedEvents = true; 265 265 foreach (var plugin in plugins.OfType<IPluginDescription>()) { 266 266 pluginListView.Items.Add(CreateListViewItem(plugin)); 267 267 } 268 269 pluginListView.CheckItems(from plugin in activeProduct.Plugins 270 let item = FindItemForPlugin(plugin) 271 where item != null 272 select item); 273 268 pluginListView.SuppressItemCheckedEvents = false; 269 foreach (var plugin in activeProduct.Plugins) { 270 pluginListView.CheckItems(FindItemsForPlugin(plugin)); 271 } 274 272 } else { 275 273 nameTextBox.Text = string.Empty; … … 277 275 pluginListView.Items.Clear(); 278 276 } 277 Util.ResizeColumns(pluginListView.Columns.OfType<ColumnHeader>()); 278 } 279 280 private void UpdateProductButtons() { 281 uploadButton.Enabled = dirtyProducts.Count > 0; 282 if (productsListView.SelectedItems.Count > 0) { 283 var selectedProduct = (DeploymentService.ProductDescription)productsListView.SelectedItems[0].Tag; 284 deleteProductButton.Enabled = !dirtyProducts.Contains(selectedProduct); 285 } else { 286 deleteProductButton.Enabled = false; 287 } 279 288 } 280 289 … … 283 292 private void newProductButton_Click(object sender, EventArgs e) { 284 293 var newProduct = new DeploymentService.ProductDescription("New product", new Version("0.0.0.0")); 285 ListViewItem item = CreateListViewItem(newProduct);286 productsListView.Items.Add(item);294 products.Add(newProduct); 295 UpdateProductsList(); 287 296 MarkProductDirty(newProduct); 288 297 } … … 359 368 360 369 #region plugin list view 361 private void pluginListView_ItemChecked(object sender,ItemCheckedEventArgs e) {370 private void OnItemChecked(ItemCheckedEventArgs e) { 362 371 ListViewItem activeItem = (ListViewItem)productsListView.SelectedItems[0]; 363 372 DeploymentService.ProductDescription activeProduct = (DeploymentService.ProductDescription)activeItem.Tag; … … 366 375 MarkProductDirty(activeProduct); 367 376 } 377 378 private void listView_ItemChecked(object sender, ItemCheckedEventArgs e) { 379 List<IPluginDescription> modifiedPlugins = new List<IPluginDescription>(); 380 if (e.Item.Checked) { 381 foreach (ListViewItem item in pluginListView.SelectedItems) { 382 var plugin = (IPluginDescription)item.Tag; 383 // also check all dependencies 384 if (!modifiedPlugins.Contains(plugin)) 385 modifiedPlugins.Add(plugin); 386 foreach (var dep in GetAllDependencies(plugin)) { 387 if (!modifiedPlugins.Contains(dep)) 388 modifiedPlugins.Add(dep); 389 } 390 } 391 pluginListView.CheckItems(modifiedPlugins.Select(x => FindItemsForPlugin(x).Single())); 392 OnItemChecked(e); 393 } else { 394 foreach (ListViewItem item in pluginListView.SelectedItems) { 395 var plugin = (IPluginDescription)item.Tag; 396 // also uncheck all dependent plugins 397 if (!modifiedPlugins.Contains(plugin)) 398 modifiedPlugins.Add(plugin); 399 foreach (var dep in GetAllDependents(plugin)) { 400 if (!modifiedPlugins.Contains(dep)) 401 modifiedPlugins.Add(dep); 402 } 403 404 } 405 pluginListView.UncheckItems(modifiedPlugins.Select(x => FindItemsForPlugin(x).Single())); 406 OnItemChecked(e); 407 } 408 } 409 410 368 411 #endregion 369 412 370 413 #region helper 414 private IEnumerable<IPluginDescription> GetAllDependents(IPluginDescription plugin) { 415 return from p in plugins 416 let matchingEntries = from dep in GetAllDependencies(p) 417 where dep.Name == plugin.Name 418 where dep.Version == plugin.Version 419 select dep 420 where matchingEntries.Any() 421 select p as IPluginDescription; 422 } 423 424 private IEnumerable<IPluginDescription> GetAllDependencies(IPluginDescription plugin) { 425 HashSet<IPluginDescription> yieldedPlugins = new HashSet<IPluginDescription>(); 426 foreach (var dep in plugin.Dependencies) { 427 foreach (var recDep in GetAllDependencies(dep)) { 428 if (!yieldedPlugins.Contains(recDep)) { 429 yieldedPlugins.Add(recDep); 430 yield return recDep; 431 } 432 } 433 if (!yieldedPlugins.Contains(dep)) { 434 yieldedPlugins.Add(dep); 435 yield return dep; 436 } 437 } 438 } 371 439 private void MarkProductDirty(HeuristicLab.PluginInfrastructure.Advanced.DeploymentService.ProductDescription activeProduct) { 372 440 if (!dirtyProducts.Contains(activeProduct)) { … … 374 442 var item = FindItemForProduct(activeProduct); 375 443 item.ImageIndex = 1; 444 UpdateProductButtons(); 376 445 } 377 446 } … … 399 468 select item).Single(); 400 469 } 401 402 private ListViewItem FindItemForPlugin(IPluginDescription plugin) { 403 return (from i in pluginListView.Items.Cast<ListViewItem>() 404 let p = i.Tag as IPluginDescription 405 where p != null 406 where p.Name == plugin.Name 407 where p.Version == plugin.Version 408 select i).SingleOrDefault(); 409 } 410 411 private void DisableControls() { 412 newProductButton.Enabled = false; 413 productsListView.Enabled = false; 414 detailsGroupBox.Enabled = false; 415 deleteProductButton.Enabled = false; 416 nameTextBox.Text = string.Empty; 417 versionTextBox.Text = string.Empty; 418 pluginListView.Items.Clear(); 419 } 470 private IEnumerable<ListViewItem> FindItemsForPlugin(IPluginDescription plugin) { 471 return from item in pluginListView.Items.OfType<ListViewItem>() 472 let p = item.Tag as IPluginDescription 473 where p.Name == plugin.Name 474 where p.Version == plugin.Version 475 select item; 476 } 477 420 478 private void EnableControls() { 421 479 newProductButton.Enabled = true;
Note: See TracChangeset
for help on using the changeset viewer.