BuildProjectsControl.cs :  » Build-Systems » CruiseControl.NET » ThoughtWorks » CruiseControl » CCTrayLib » Presentation » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Build Systems » CruiseControl.NET 
CruiseControl.NET » ThoughtWorks » CruiseControl » CCTrayLib » Presentation » BuildProjectsControl.cs
using System;
using System.Windows.Forms;
using ThoughtWorks.CruiseControl.CCTrayLib.Configuration;

namespace ThoughtWorks.CruiseControl.CCTrayLib.Presentation{
  public partial class BuildProjectsControl : UserControl
  {
    private ProjectConfigurationListViewItemAdaptor selected;
    private int selectedIndex = -1;
    private ICCTrayMultiConfiguration configuration;

    public BuildProjectsControl()
    {
      InitializeComponent();
    }

    public void BindListView(ICCTrayMultiConfiguration configuration)
    {
      this.configuration = configuration;

      lvProjects.Items.Clear();

      foreach (CCTrayProject project in configuration.Projects)
      {
        lvProjects.Items.Add(new ProjectConfigurationListViewItemAdaptor(project).Item);
      }

      UpdateButtons();
    }

    private void lvProjects_SelectedIndexChanged(object sender, EventArgs e)
    {
      if (lvProjects.SelectedItems.Count == 0)
      {
        selected = null;
        selectedIndex = -1;
      }
      else
      {
        selected = (ProjectConfigurationListViewItemAdaptor)lvProjects.SelectedItems[0].Tag;
        selectedIndex = lvProjects.SelectedIndices[0];
      }

      UpdateButtons();
    }

    private void UpdateButtons()
    {
      btnRemove.Enabled = selected != null;

      if (selected != null)
      {
        btnMoveDown.Enabled = selectedIndex < (lvProjects.Items.Count - 1);
        btnMoveUp.Enabled = selectedIndex != 0;
      }
      else
      {
        btnMoveDown.Enabled = btnMoveUp.Enabled = false;
      }
    }

    private void btnRemove_Click(object sender, EventArgs e)
    {
      lvProjects.BeginUpdate();
      foreach (ListViewItem item in lvProjects.SelectedItems)
      {
        lvProjects.Items.Remove(item);
      }
      lvProjects.EndUpdate();
    }

    private void btnMoveUp_Click(object sender, EventArgs e)
    {
      MoveSelectedItem(-1);
    }

    private void btnMoveDown_Click(object sender, EventArgs e)
    {
      MoveSelectedItem(+1);
    }

    private void MoveSelectedItem(int delta)
    {
      ProjectConfigurationListViewItemAdaptor currentlySelected = selected;
      int reinsertIndex = selectedIndex + delta;

      lvProjects.Items.RemoveAt(selectedIndex);
      lvProjects.Items.Insert(reinsertIndex, currentlySelected.Item);
    }

    private void btnAdd_Click(object sender, EventArgs e)
    {
      AddProjects addProjectDialog = new AddProjects(
                configuration.CruiseProjectManagerFactory, 
                configuration.CruiseServerManagerFactory,
                BuildProjectListFromListView());
      CCTrayProject[] projects = addProjectDialog.GetListOfNewProjects(this);

      if (projects != null)
      {
        foreach (CCTrayProject newProject in projects)
        {
          lvProjects.Items.Add(new ProjectConfigurationListViewItemAdaptor(newProject).Item);
        }
      }
    }

    private CCTrayProject[] BuildProjectListFromListView()
    {
      CCTrayProject[] newProjectList = new CCTrayProject[lvProjects.Items.Count];

      for (int i = 0; i < lvProjects.Items.Count; i++)
      {
        ProjectConfigurationListViewItemAdaptor adaptor = (ProjectConfigurationListViewItemAdaptor)lvProjects.Items[i].Tag;
        newProjectList[i] = adaptor.Project;
      }
      return newProjectList;
    }

    private void lvProjects_ItemChecked(object sender, ItemCheckedEventArgs e)
    {
      foreach (CCTrayProject project in configuration.Projects)
      {
        if (e.Item.SubItems[2].Text == project.ProjectName)
        {
          project.ShowProject = e.Item.Checked;
        }
      }
    }

    private void lvProjects_KeyDown(object sender, KeyEventArgs e)
    {
      if(KeyUtils.PressedControlA(e))
      {
        // Select all items.
        foreach (ListViewItem item in lvProjects.Items)
          item.Selected = true;
      }
      else
      if (e.KeyCode == Keys.Delete)
      {
        // Delete selected items.
        lvProjects.BeginUpdate();
        foreach (ListViewItem item in lvProjects.SelectedItems)
          lvProjects.Items.Remove(item);

        lvProjects.EndUpdate();
      }
    }

    private void chkCheck_CheckedChanged(object sender, EventArgs e)
    {
      if (chkCheckAllProjects.Checked)
      {
        foreach (ListViewItem item in lvProjects.Items)
        {
          item.Checked = true;
        }
      }
      else
      {
      foreach (ListViewItem item in lvProjects.Items)
        {
          item.Checked = false;
        }
      }
    }

    public void PersistProjectTabSettings()
    {
      CCTrayProject[] newProjectList = BuildProjectListFromListView();
      configuration.Projects = newProjectList;
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.