Skip to main content
summaryrefslogtreecommitdiffstats
blob: 5221f86b29874b19474886dfa1dd097017cd8a78 (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
/*******************************************************************************
 * Copyright (c) 2010 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.core.dsl.ui.integration.internal;

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.logging.Level;
import org.eclipse.osee.framework.core.data.IAttributeType;
import org.eclipse.osee.framework.core.data.IOseeBranch;
import org.eclipse.osee.framework.core.dsl.integration.ArtifactDataProvider;
import org.eclipse.osee.framework.core.model.Branch;
import org.eclipse.osee.framework.core.model.IBasicArtifact;
import org.eclipse.osee.framework.core.model.type.ArtifactType;
import org.eclipse.osee.framework.core.model.type.RelationType;
import org.eclipse.osee.framework.jdk.core.type.Identity;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.skynet.core.OseeSystemArtifacts;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;

public final class ArtifactDataProviderImpl implements ArtifactDataProvider {

   @Override
   public boolean isApplicable(Object object) {
      boolean result = false;
      try {
         result = asCastedObject(object) != null;
      } catch (OseeCoreException ex) {
         OseeLog.log(DslUiIntegrationConstants.class, Level.SEVERE, ex);
      }
      return result;
   }

   @Override
   public ArtifactProxy asCastedObject(Object object) throws OseeCoreException {
      XArtifactProxy proxy = null;
      if (object instanceof Artifact) {
         final Artifact artifact = (Artifact) object;
         proxy = new XArtifactProxy(artifact);
      } else if (object instanceof IOseeBranch) {
         IOseeBranch branch = (Branch) object;
         final Artifact artifact = OseeSystemArtifacts.getDefaultHierarchyRootArtifact(branch);
         proxy = new XArtifactProxy(artifact);
      }
      return proxy;
   }

   private final class XArtifactProxy implements ArtifactProxy {
      private final Artifact self;

      public XArtifactProxy(Artifact self) {
         this.self = self;
      }

      @Override
      public String getGuid() {
         return self.getGuid();
      }

      @Override
      public ArtifactType getArtifactType() {
         return self.getArtifactType();
      }

      @Override
      public boolean isAttributeTypeValid(IAttributeType attributeType) throws OseeCoreException {
         return self.isAttributeTypeValid(attributeType);
      }

      @Override
      public Collection<RelationType> getValidRelationTypes() throws OseeCoreException {
         return self.getValidRelationTypes();
      }

      @Override
      public IBasicArtifact<?> getObject() {
         return self;
      }

      @Override
      public Collection<ArtifactProxy> getHierarchy() {
         Collection<ArtifactProxy> hierarchy = new HashSet<ArtifactProxy>();
         try {
            Artifact artifactPtr = self.getParent();
            while (artifactPtr != null) {
               if (!hierarchy.add(new XArtifactProxy(artifactPtr))) {
                  OseeLog.log(DslUiIntegrationConstants.class, Level.SEVERE,
                     String.format("Cycle detected with artifact: %s", artifactPtr));
                  return Collections.emptyList();
               }
               artifactPtr = artifactPtr.getParent();
            }
         } catch (OseeCoreException ex) {
            OseeLog.log(DslUiIntegrationConstants.class, Level.SEVERE, ex);
         }
         return hierarchy;
      }

      @Override
      public boolean matches(Identity<?>... identities) {
         return self.matches(identities);
      }

      @Override
      public IOseeBranch getBranch() {
         return self.getBranch();
      }

      @Override
      public String getName() {
         return self.getName();
      }

      @Override
      public int hashCode() {
         return self.hashCode();
      }

      @Override
      public boolean equals(Object obj) {
         return self.equals(obj);
      }

      @Override
      public String toString() {
         return self.toString();
      }

      @Override
      public long getUuid() {
         return self.getArtId();
      }
   }
}

Back to the top