Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/15/09 14:37:04 (15 years ago)
Author:
aleitner
Message:

add contextmenu for adding/deleting groups (#626)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Hive.Server.Console/3.2/HiveServerManagementConsole.cs

    r1774 r1832  
    5858    private Job currentJob = null;
    5959    private ClientInfo currentClient = null;
    60    
     60
    6161    TreeNode currentNode = null;
    6262
     
    132132      };
    133133
     134      //adding group
     135      menuItemAddGroup.Click += (s, e) => {
     136        AddGroup addgroup = new AddGroup();
     137        parentgroup = Guid.Empty;
     138        if ((tvClientControl.SelectedNode != null) && (((ClientGroup)tvClientControl.SelectedNode.Tag).Id != Guid.Empty)) {
     139          parentgroup = ((ClientGroup)tvClientControl.SelectedNode.Tag).Id;
     140        }
     141        addgroup.addGroupEvent += new AddGroupDelegate(addgroup_addGroupEvent);
     142        addgroup.Show();
     143      };
     144
     145      //adding group
     146      menuItemDeleteGroup.Click += (s, e) => {
     147        IClientManager clientManager = ServiceLocator.GetClientManager();
     148        if (tvClientControl.SelectedNode != null) {
     149          //  Delete Group
     150        }
     151      };
     152    }
     153
     154    Guid parentgroup = Guid.Empty;
     155
     156    void addgroup_addGroupEvent(string name) {
     157      IClientManager clientManager = ServiceLocator.GetClientManager();
     158
     159      if (parentgroup != Guid.Empty) {
     160        ClientGroup cg = new ClientGroup() { Name = name };
     161        ResponseObject<ClientGroup> respcg = clientManager.AddClientGroup(cg);
     162        Response res = clientManager.AddResourceToGroup(parentgroup, respcg.Obj);
     163        if (res != null && !res.Success) {
     164          MessageBox.Show(res.StatusMessage, "Error adding Group", MessageBoxButtons.OK, MessageBoxIcon.Error);
     165        }
     166      } else {
     167        ClientGroup cg = new ClientGroup() { Name = name };
     168        clientManager.AddClientGroup(cg);
     169      }
     170
    134171    }
    135172
     
    150187    }
    151188
    152     ///// <summary>
    153     ///// Adds clients to ListView and TreeView
    154     ///// </summary>
    155     //private void AddClients() {
    156     //  try {
    157     //    clientObjects = new Dictionary<Guid, ListViewGroup>();
    158     //    clientInfoObjects = new Dictionary<Guid, ListViewItem>();
    159 
    160     //    clients = ClientManager.GetAllClientGroups();
    161 
    162     //    List<Guid> inGroup = new List<Guid>();
    163     //    foreach (ClientGroup cg in clients.List) {
    164     //      TreeNode tn = new TreeNode(cg.Name);
    165     //      tn.Tag = cg;
    166     //      tvClientControl.Nodes.Add(tn);
    167 
    168     //      ListViewGroup lvg = new ListViewGroup(cg.Name, HorizontalAlignment.Left);
    169 
    170     //      foreach (ClientInfo ci in cg.Resources) {
    171     //        ListViewItem item = null;
    172     //        if ((ci.State == State.offline) || (ci.State == State.nullState)) {
    173     //          item = new ListViewItem(ci.Name, 3, lvg);
    174     //        } else {
    175     //          int percentageUsage = CapacityRam(ci.NrOfCores, ci.NrOfFreeCores);
    176     //          int usage = 0;
    177     //          if ((percentageUsage >= 0) && (percentageUsage <= 25)) {
    178     //            usage = 0;
    179     //          } else if ((percentageUsage > 25) && (percentageUsage <= 75)) {
    180     //            usage = 1;
    181     //          } else if ((percentageUsage > 75) && (percentageUsage <= 100)) {
    182     //            usage = 2;
    183     //          }
    184 
    185     //          item = new ListViewItem(ci.Name, usage, lvg);
    186     //        }
    187     //        item.Tag = ci.Id;
    188     //        lvClientControl.Items.Add(item);
    189     //        clientInfoObjects.Add(ci.Id, item);
    190     //        inGroup.Add(ci.Id);
    191 
    192     //      }
    193     //      lvClientControl.BeginUpdate();
    194     //      lvClientControl.Groups.Add(lvg);
    195     //      lvClientControl.EndUpdate();
    196     //      clientObjects.Add(cg.Id, lvg);
    197     //    } // Groups
    198 
    199     //    clientInfo = ClientManager.GetAllClients();
    200     //    ListViewGroup lvunsorted = new ListViewGroup("no group", HorizontalAlignment.Left);
    201     //    foreach (ClientInfo ci in clientInfo.List) {
    202     //      bool help = false;
    203     //      foreach (Guid client in inGroup) {
    204     //        if (client == ci.Id) {
    205     //          help = true;
    206     //          break;
    207     //        }
    208     //      }
    209     //      if (!help) {
    210     //        ListViewItem item = null;
    211     //        if ((ci.State == State.offline) || (ci.State == State.nullState)) {
    212     //          item = new ListViewItem(ci.Name, 3, lvunsorted);
    213     //        } else {
    214     //          int percentageUsage = CapacityRam(ci.NrOfCores, ci.NrOfFreeCores);
    215     //          int usage = 0;
    216     //          if ((percentageUsage >= 0) && (percentageUsage <= 25)) {
    217     //            usage = 0;
    218     //          } else if ((percentageUsage > 25) && (percentageUsage <= 75)) {
    219     //            usage = 1;
    220     //          } else if ((percentageUsage > 75) && (percentageUsage <= 100)) {
    221     //            usage = 2;
    222     //          }
    223     //          item = new ListViewItem(ci.Name, usage, lvunsorted);
    224     //        }
    225     //        item.Tag = ci.Id;
    226     //        lvClientControl.Items.Add(item);
    227     //      }
    228     //    }
    229     //    lvClientControl.BeginUpdate();
    230     //    lvClientControl.Groups.Add(lvunsorted);
    231     //    lvClientControl.EndUpdate();
    232     //    if (flagClient) {
    233     //      ClientClicked();
    234     //    }
    235     //  }
    236     //  catch (Exception ex) {
    237     //    closeFormEvent(true, true);
    238     //    this.Close();
    239     //  }
    240     //}
    241 
    242189    private void AddClients() {
    243190      clientList.Clear();
     
    256203      }
    257204      tvClientControl.ExpandAll();
    258       Thread.Sleep(5000);
    259205    }
    260206
     
    343289            lvi.ToolTipText = (job.Percentage * 100) + "% of job calculated";
    344290          } else if (job.State == State.finished) {
    345             ListViewItem lvi = new ListViewItem(job.Id.ToString(),0, lvJobFinished);
     291            ListViewItem lvi = new ListViewItem(job.Id.ToString(), 0, lvJobFinished);
    346292            lvi.Tag = job;
    347293            jobObjects.Add(job.Id, lvi);
     
    385331        currentClient = (ClientInfo)lvClientControl.SelectedItems[0].Tag;
    386332      }
    387       if(currentClient != null) {
    388       int percentageUsage = CapacityRam(currentClient.NrOfCores, currentClient.NrOfFreeCores);
    389       int usage = 3;
    390       if ((currentClient.State != State.offline) && (currentClient.State != State.nullState)) {
    391         if ((percentageUsage >= 0) && (percentageUsage <= 25)) {
    392           usage = 0;
    393         } else if ((percentageUsage > 25) && (percentageUsage <= 75)) {
    394           usage = 1;
    395         } else if ((percentageUsage > 75) && (percentageUsage <= 100)) {
    396           usage = 2;
    397         }
    398       }
    399       pbClientControl.Image = ilLargeImgClient.Images[usage];
    400       lblClientName.Text = currentClient.Name;
    401       lblLogin.Text = currentClient.Login.ToString();
    402       lblState.Text = currentClient.State.ToString();
     333      if (currentClient != null) {
     334        int percentageUsage = CapacityRam(currentClient.NrOfCores, currentClient.NrOfFreeCores);
     335        int usage = 3;
     336        if ((currentClient.State != State.offline) && (currentClient.State != State.nullState)) {
     337          if ((percentageUsage >= 0) && (percentageUsage <= 25)) {
     338            usage = 0;
     339          } else if ((percentageUsage > 25) && (percentageUsage <= 75)) {
     340            usage = 1;
     341          } else if ((percentageUsage > 75) && (percentageUsage <= 100)) {
     342            usage = 2;
     343          }
     344        }
     345        pbClientControl.Image = ilLargeImgClient.Images[usage];
     346        lblClientName.Text = currentClient.Name;
     347        lblLogin.Text = currentClient.Login.ToString();
     348        lblState.Text = currentClient.State.ToString();
    403349      }
    404350    }
     
    437383      lvJobDetails.Items.Add(lvi);
    438384
    439         lvi = null;
    440         lvi = new ListViewItem();
    441         lvi.Text = "created at:";
    442         lvi.SubItems.Add(currentJob.DateCreated.ToString());
    443         lvJobDetails.Items.Add(lvi);
     385      lvi = null;
     386      lvi = new ListViewItem();
     387      lvi.Text = "created at:";
     388      lvi.SubItems.Add(currentJob.DateCreated.ToString());
     389      lvJobDetails.Items.Add(lvi);
    444390
    445391      if (currentJob.ParentJob != null) {
     
    449395        lvi.SubItems.Add(currentJob.ParentJob.ToString());
    450396        lvJobDetails.Items.Add(lvi);
    451      // lblParentJob.Text = currentJob.ParentJob.Id + " is parent job";
     397        // lblParentJob.Text = currentJob.ParentJob.Id + " is parent job";
    452398      }// else {
    453399      //  lblParentJob.Text = "";
     
    460406      lvJobDetails.Items.Add(lvi);
    461407
    462      // lblPriorityJob.Text = "Priority of job is " + currentJob.Priority;
     408      // lblPriorityJob.Text = "Priority of job is " + currentJob.Priority;
    463409      if (currentJob.Client != null) {
    464410        lvi = null;
     
    482428            ServiceLocator.GetJobManager();
    483429          ResponseObject<JobResult> jobRes = jobManager.GetLastJobResultOf(currentJob.Id, false);
    484          
     430
    485431          lvi = null;
    486432          lvi = new ListViewItem();
     
    488434          lvi.SubItems.Add(jobRes.Obj.DateFinished.ToString());
    489435          lvJobDetails.Items.Add(lvi);
    490          // lblJobCalculationEnd.Text = "Calculation ended at " + jobRes.Obj.DateFinished;
     436          // lblJobCalculationEnd.Text = "Calculation ended at " + jobRes.Obj.DateFinished;
    491437        }
    492438      } else {
    493        // lblClientCalculating.Text = "";
    494        // lblJobCalculationBegin.Text = "";
    495        // lblJobCalculationEnd.Text = "";
     439        // lblClientCalculating.Text = "";
     440        // lblJobCalculationBegin.Text = "";
     441        // lblJobCalculationEnd.Text = "";
    496442      }
    497443      if (currentJob.State != State.offline) {
    498444        lvSnapshots.Items.Clear();
    499         if (currentJob.State == State.finished)
    500           GetSnapshotList();
    501         lvSnapshots.Visible = true;
     445        //if (currentJob.State == State.finished)
     446        GetSnapshotList();
     447        //lvSnapshots.Visible = true;
    502448      } else {
    503449        lvSnapshots.Visible = false;
     
    686632      //ResponseList<ClientGroup> clientsOld = clients;
    687633
    688      // newClients = ClientManager.GetAllClientGroups();
     634      // newClients = ClientManager.GetAllClientGroups();
    689635
    690636      //IDictionary<Guid, ClientGroup> clientsOldHelp;
     
    795741
    796742    private void DetermineDelta() {
    797      
    798 
    799 
    800     }
    801 
     743
     744    }
    802745
    803746    //private void GetDelta(IList<ClientGroup> oldClient, IDictionary<Guid, ClientGroup> helpClients) {
     
    896839      IJobManager jobManager = ServiceLocator.GetJobManager();
    897840
    898       ResponseObject<JobResult> jobRes = jobManager.GetLastJobResultOf(currentJob.Id, false);
    899 
    900       // iterate threw all snapshots if method is implemented
    901 
    902       ListViewItem curSnapshot = new ListViewItem(jobRes.Obj.Client.Name);
    903       double percentage = jobRes.Obj.Percentage * 100;
    904       curSnapshot.SubItems.Add(percentage.ToString() + " %");
    905       curSnapshot.SubItems.Add(jobRes.Obj.Timestamp.ToString());
    906       lvSnapshots.Items.Add(curSnapshot);
     841      ResponseList<JobResult> jobRes = jobManager.GetAllJobResults(currentJob.Id);
     842
     843      if (jobRes.List != null) {
     844        foreach (JobResult jobresult in jobRes.List) {
     845          ListViewItem curSnapshot = new ListViewItem(jobresult.Client.Name);
     846          double percentage = jobresult.Percentage * 100;
     847          curSnapshot.SubItems.Add(percentage.ToString() + " %");
     848          curSnapshot.SubItems.Add(jobresult.Timestamp.ToString());
     849          lvSnapshots.Items.Add(curSnapshot);
     850        }
     851      }
     852
     853      if ((jobRes.List == null) && (jobRes.List.Count == 0)) {
     854        lvSnapshots.Visible = false;
     855      } else {
     856        lvSnapshots.Visible = true;
     857      }
     858
    907859    }
    908860
     
    959911    private void Refresh_Click(object sender, EventArgs e) {
    960912      Form overlayingForm = new Form();
    961       //Label loadingLabel = new Label();
    962       //loadingLabel.Text = "Loading";
    963       //loadingLabel.Font = new System.Drawing.Font("Microsoft Sans Serif", 20F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
    964       //loadingLabel.Location = new Point(this.Width / 2, this.Height / 2);
    965       //overlayingForm.Controls.Add(loadingLabel);
    966 
    967913
    968914      overlayingForm.Show();
     
    971917      overlayingForm.Opacity = 0.4;
    972918      overlayingForm.Size = this.Size;
    973       //overlayingForm.PointToClient(new Point(this.Left, this.Top));
    974919      overlayingForm.Location = this.Location;
    975       Console.WriteLine(this.Left + ", " + this.Top);
    976       //overlayingForm.Left = this.Left;
    977       //overlayingForm.Top = this.Top;
    978 
    979      
    980      
    981 
     920
     921      //Label lbl = new Label();
     922      //overlayingForm.Controls.Add(lbl);
     923      //lbl.AutoSize = true;
     924      //lbl.Text = "Loading";
     925      //lbl.Name = "lblName";
     926      //lbl.Font = new System.Drawing.Font("Microsoft Sans Serif", 20F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
     927      //lbl.ForeColor = Color.Black;
     928      //lbl.BackColor = Color.Transparent;
     929      //lbl.Location = new Point(overlayingForm.Width / 2, overlayingForm.Height / 2);
    982930
    983931      AddClients();
    984932
    985933      overlayingForm.Close();
     934    }
     935
     936    private void tvClientControl_MouseUp(object sender, MouseEventArgs e) {
     937      // If the right mouse button was clicked and released,
     938      // display the shortcut menu assigned to the ListView.
     939      contextMenuGroup.Items.Clear();
     940      TreeViewHitTestInfo hitTestInfo = tvClientControl.HitTest(e.Location);
     941      tvClientControl.SelectedNode = hitTestInfo.Node;
     942      if (e.Button != MouseButtons.Right) return;
     943        if (hitTestInfo.Node != null) {
     944          Resource selectedGroup = (Resource)tvClientControl.SelectedNode.Tag;
     945
     946          if (selectedGroup != null) {
     947            contextMenuGroup.Items.Add(menuItemAddGroup);
     948            contextMenuGroup.Items.Add(menuItemDeleteGroup);
     949          }
     950        } else {
     951          contextMenuGroup.Items.Add(menuItemAddGroup);
     952        }
     953        tvClientControl.ContextMenuStrip.Show(new Point(e.X, e.Y));
    986954    }
    987955  }
Note: See TracChangeset for help on using the changeset viewer.