Skip to main content
summaryrefslogtreecommitdiffstats
blob: ada7d0842d5e5f1949bf8c7acfea8a1e2eb11fb3 (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
/*******************************************************************************
 * 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.coverage.editor;

import java.util.ArrayList;
import java.util.List;
import org.eclipse.osee.coverage.store.CoverageArtifactTypes;
import org.eclipse.osee.coverage.util.CoverageImage;
import org.eclipse.osee.framework.access.AccessControlManager;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.ui.skynet.render.DefaultArtifactRenderer;
import org.eclipse.osee.framework.ui.skynet.render.PresentationType;
import org.eclipse.osee.framework.ui.swt.ImageManager;
import org.eclipse.swt.graphics.Image;

/**
 * @author Ryan D. Brooks
 */
public class CoverageRenderer extends DefaultArtifactRenderer {
   private static final String COMMAND_ID = "org.eclipse.osee.coverage.editor.command";

   @Override
   public List<String> getCommandId(PresentationType presentationType) {
      ArrayList<String> commandIds = new ArrayList<String>(1);

      if (presentationType == PresentationType.SPECIALIZED_EDIT) {
         commandIds.add(COMMAND_ID);
      }

      return commandIds;
   }

   @Override
   public Image getImage(Artifact artifact) throws OseeCoreException {
      return ImageManager.getImage(CoverageImage.COVERAGE_PACKAGE);
   }

   @Override
   public String getName() {
      return "Coverage Editor";
   }

   public CoverageRenderer() {
      super();
   }

   @Override
   public void open(List<Artifact> artifacts) throws OseeCoreException {
      for (Artifact artifact : artifacts) {
         if (artifact.isOfType(CoverageArtifactTypes.CoveragePackage) || //
         artifact.isOfType(CoverageArtifactTypes.CoverageFolder) || //
         artifact.isOfType(CoverageArtifactTypes.CoverageUnit)) {
            recurseAndOpenCoveragePackage(artifact);
         }
      }
   }

   private void recurseAndOpenCoveragePackage(Artifact artifact) throws OseeCoreException {
      if (artifact.isOfType(CoverageArtifactTypes.CoveragePackage)) {
         CoverageEditor.open(new CoverageEditorInput(artifact.getName(), artifact, null, false));
      } else {
         if (artifact.getParent() != null) {
            recurseAndOpenCoveragePackage(artifact.getParent());
         }
      }
   }

   @Override
   public CoverageRenderer newInstance() throws OseeCoreException {
      return new CoverageRenderer();
   }

   @Override
   public int getApplicabilityRating(PresentationType presentationType, Artifact artifact) throws OseeCoreException {
      if ((artifact.isOfType(CoverageArtifactTypes.CoveragePackage) || //
      artifact.isOfType(CoverageArtifactTypes.CoverageFolder) || //
      artifact.isOfType(CoverageArtifactTypes.CoverageUnit)) && !artifact.isHistorical()) {
         return PRESENTATION_SUBTYPE_MATCH;
      }
      return NO_MATCH;
   }

   @Override
   public void preview(List<Artifact> artifacts) throws OseeCoreException {
      open(artifacts);
   }

   @Override
   public int minimumRanking() throws OseeCoreException {
      if (AccessControlManager.isOseeAdmin()) {
         return NO_MATCH;
      } else {
         return PRESENTATION_TYPE;
      }
   }
}

Back to the top