Skip to main content
summaryrefslogtreecommitdiffstats
blob: 907f57d3a85145e2ad7b838237dfbea787580beb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*******************************************************************************
 * Copyright (c) 2004, 2007 Boeing.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Boeing - initial API and implementation
 *******************************************************************************/

package org.eclipse.osee.ats.util.widgets.dialog;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.eclipse.osee.ats.api.ai.IAtsActionableItem;
import org.eclipse.osee.ats.core.config.ActionableItems;
import org.eclipse.osee.ats.util.AtsObjectLabelProvider;
import org.eclipse.osee.framework.core.enums.Active;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.ui.skynet.util.ArtifactNameSorter;
import org.eclipse.osee.framework.ui.skynet.util.filteredTree.OSEECheckedFilteredTreeDialog;
import org.eclipse.osee.framework.ui.skynet.widgets.XCheckBox;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;

/**
 * @author Donald G. Dunne
 */
public class ActionableItemTreeWithChildrenDialog extends OSEECheckedFilteredTreeDialog {

   XCheckBox recurseChildrenCheck = new XCheckBox("Include all children Actionable Item Actions");
   boolean recurseChildren = false;
   protected Composite dialogComp;

   public ActionableItemTreeWithChildrenDialog(Active active) throws OseeCoreException {
      this(active, ActionableItems.getTopLevelActionableItems(active));
   }

   public ActionableItemTreeWithChildrenDialog(Active active, Collection<IAtsActionableItem> actionableItems) {
      super("Select Actionable Item", "Select Actionable Item", new ActionableItemTreeContentProvider(active),
         new AtsObjectLabelProvider(), new ArtifactNameSorter());
      setInput(actionableItems);
   }

   /**
    * @return selected AIs and children if recurseChildren was checked
    */
   public Collection<IAtsActionableItem> getResultAndRecursedAIs() throws OseeCoreException {
      Set<IAtsActionableItem> aias = new HashSet<IAtsActionableItem>(10);
      for (Object obj : getResult()) {
         IAtsActionableItem ai = (IAtsActionableItem) obj;
         aias.add(ai);
         if (recurseChildren) {
            aias.addAll(ActionableItems.getChildren(ai, true));
         }
      }
      return aias;
   }

   @Override
   protected Control createDialogArea(Composite container) {

      Control control = super.createDialogArea(container);
      dialogComp = new Composite(control.getParent(), SWT.NONE);
      dialogComp.setLayout(new GridLayout(2, false));
      dialogComp.setLayoutData(new GridData(GridData.FILL_BOTH));

      recurseChildrenCheck.createWidgets(dialogComp, 2);
      recurseChildrenCheck.set(recurseChildren);
      recurseChildrenCheck.addSelectionListener(new SelectionAdapter() {

         @Override
         public void widgetSelected(SelectionEvent e) {
            recurseChildren = recurseChildrenCheck.isSelected();
         };
      });

      return container;
   }

   public boolean isRecurseChildren() {
      return recurseChildren;
   }

   public void setRecurseChildren(boolean recurseChildren) {
      this.recurseChildren = recurseChildren;
   }

}

Back to the top