Skip to main content
summaryrefslogtreecommitdiffstats
blob: a454e9934b914243ec0dc472487dc37713de0dd9 (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*******************************************************************************
 * 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.framework.ui.skynet.skywalker;

import java.util.Collection;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.osee.framework.core.data.RelationTypeSide;
import org.eclipse.osee.framework.core.model.type.RelationType;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.relation.RelationManager;
import org.eclipse.osee.framework.skynet.core.types.IArtifact;
import org.eclipse.osee.framework.ui.skynet.internal.Activator;
import org.eclipse.zest.core.viewers.IGraphEntityContentProvider;

/**
 * @author Robert A. Fisher
 * @author Donald G. Dunne
 */
public class ArtifactGraphContentProvider implements IGraphEntityContentProvider {

   private final SkyWalkerOptions options;

   public ArtifactGraphContentProvider(SkyWalkerOptions options) {
      super();
      this.options = options;
   }

   @SuppressWarnings("deprecation")
   @Override
   public Object[] getConnectedTo(Object entity) {
      List<Artifact> otherItems = new LinkedList<>();

      // Don't want to create any links to artifacts that are NOT in displayArtifacts
      try {
         Artifact artifact = (Artifact) entity;
         for (Object obj : options.getSelectedRelTypes()) {
            if (obj instanceof RelationType) {
               RelationType relationType = (RelationType) obj;
               if (options.isValidRelationType(relationType)) {
                  for (IArtifact art : artifact.getRelatedArtifacts(relationType)) {
                     if (options.isValidArtifactType(art.getArtifactType()) && displayArtifacts.contains(art)) {
                        otherItems.add(art.getFullArtifact());
                     }
                  }
               }
            }
            if (obj instanceof RelationTypeSide) {
               RelationTypeSide side = (RelationTypeSide) obj;
               if (options.isValidRelationLinkDescriptorSide(side)) {
                  for (Artifact art : RelationManager.getRelatedArtifacts(artifact, side)) {
                     if (options.isValidArtifactType(art.getArtifactType()) && displayArtifacts.contains(art)) {
                        otherItems.add(art);
                     }
                  }
               }
            }
         }

      } catch (OseeCoreException ex) {
         OseeLog.log(Activator.class, Level.SEVERE, ex);
      }
      return otherItems.toArray();
   }
   private final Set<Artifact> displayArtifacts = new HashSet<>();

   @Override
   public Object[] getElements(Object inputElement) {
      // Only perform this method for top level artifact
      if (inputElement.equals(options.getArtifact())) {
         displayArtifacts.clear();
         displayArtifacts.add((Artifact) inputElement);
         getDescendants(displayArtifacts, (Artifact) inputElement, options.getLevels());
         return displayArtifacts.toArray();
      }
      return null;
   }

   @SuppressWarnings("deprecation")
   private void getDescendants(Collection<Artifact> displayArtifacts, Artifact artifact, int level) {
      if (level == 0) {
         return;
      } else {
         try {
            for (Object obj : options.getSelectedRelTypes()) {
               if (obj instanceof RelationType) {
                  RelationType relationType = (RelationType) obj;
                  if (options.isValidRelationType(relationType)) {
                     for (IArtifact art : artifact.getRelatedArtifacts(relationType)) {
                        if (options.isValidArtifactType(art.getArtifactType())) {
                           Artifact relatedArt = art.getFullArtifact();
                           displayArtifacts.add(relatedArt);
                           getDescendants(displayArtifacts, relatedArt, level - 1);
                        }
                     }
                  }
               }
               if (obj instanceof RelationTypeSide) {
                  RelationTypeSide side = (RelationTypeSide) obj;
                  if (options.isValidRelationLinkDescriptorSide(side)) {
                     for (Artifact art : RelationManager.getRelatedArtifacts(artifact, side)) {
                        if (options.isValidArtifactType(art.getArtifactType())) {
                           displayArtifacts.add(art);
                           getDescendants(displayArtifacts, art, level - 1);
                        }
                     }
                  }
               }
            }
         } catch (OseeCoreException ex) {
            OseeLog.log(Activator.class, Level.SEVERE, ex);
         }
      }
   }

   public double getWeight(Object entity1, Object entity2) {
      return 0;
   }

   @Override
   public void dispose() {
      // do nothing
   }

   @Override
   public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
      // do nothing
   }

}

Back to the top