Skip to main content
summaryrefslogtreecommitdiffstats
blob: 0e766586b9a31623403c59ad78784a8e4e340a8b (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
/*******************************************************************************
 * 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.search.page;

import java.util.ArrayList;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.artifact.Attribute;
import org.eclipse.osee.framework.ui.skynet.search.AbstractArtifactSearchResult;
import org.eclipse.search.ui.text.Match;

/**
 * @author Roberto E. Escobar
 */
public class AttributeLineElement implements IAdaptable {

   private final int attribute;
   private final Artifact parent;
   private final int lineNumber;
   private final int lineStartOffset;
   private final String lineContents;

   public AttributeLineElement(Artifact parent, int attribute, int lineNumber, int lineStartOffset, String contents) {
      this.parent = parent;
      this.attribute = attribute;
      this.lineContents = contents;
      this.lineNumber = lineNumber;
      this.lineStartOffset = lineStartOffset;
   }

   public Artifact getParent() {
      return parent;
   }

   public int getLine() {
      return lineNumber;
   }

   public String getContents() {
      return lineContents;
   }

   public int getOffset() {
      return lineStartOffset;
   }

   public boolean contains(int offset) {
      return lineStartOffset <= offset && offset < lineStartOffset + lineContents.length();
   }

   public int getLength() {
      return lineContents.length();
   }

   public AttributeMatch[] getMatches(AbstractArtifactSearchResult result) {
      ArrayList<AttributeMatch> res = new ArrayList<>();
      Match[] matches = result.getMatches(parent);
      for (int i = 0; i < matches.length; i++) {
         AttributeMatch curr = (AttributeMatch) matches[i];
         if (curr.getLineElement() == this) {
            res.add(curr);
         }
      }
      return res.toArray(new AttributeMatch[res.size()]);
   }

   public int getNumberOfMatches(AbstractArtifactSearchResult result) {
      int count = 0;
      Match[] matches = result.getMatches(parent);
      for (int i = 0; i < matches.length; i++) {
         AttributeMatch curr = (AttributeMatch) matches[i];
         if (curr.getLineElement() == this) {
            count++;
         }
      }
      return count;
   }

   public int getAttribute() {
      return attribute;
   }

   @Override
   @SuppressWarnings("rawtypes")
   public Object getAdapter(Class adapter) {
      if (adapter == Artifact.class) {
         return getParent();
      } else if (adapter == Attribute.class) {
         return getAttribute();
      }
      return null;
   }

}

Back to the top