Skip to main content
summaryrefslogtreecommitdiffstats
blob: 9b7b2b3106e353c69320cf3d0510d7a3b0519f6d (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
/*******************************************************************************
 * 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;

import java.util.ArrayList;
import java.util.List;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.ui.skynet.artifact.editor.ArtifactEditorInput;
import org.eclipse.search.ui.text.AbstractTextSearchResult;
import org.eclipse.search.ui.text.IEditorMatchAdapter;
import org.eclipse.search.ui.text.IFileMatchAdapter;
import org.eclipse.search.ui.text.Match;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;

/**
 * @author Michael S. Rodgers
 */
public abstract class AbstractArtifactSearchResult extends AbstractTextSearchResult implements IEditorMatchAdapter {
   private final Match[] EMPTY_ARR = new Match[0];

   /**
    * Constructs a new <code>AbstractTextSearchResult</code>
    */
   protected AbstractArtifactSearchResult() {
      super();
   }

   public List<Artifact> getArtifactResults() {
      List<Artifact> toReturn = new ArrayList<Artifact>();
      for (Object element : getElements()) {
         if (element instanceof Artifact) {
            toReturn.add((Artifact) element);
         }
      }
      return toReturn;
   }

   //   /**
   //    * Removes the children artifacts from the search
   //    * 
   //   //    */
   //   public void removeArtifacts(Collection<Artifact> children) {
   //      for (Artifact artifact : children) {
   //         Match match = artifacts.get(artifact);
   //         removeMatch(match);
   //         artifacts.remove(artifact);
   //
   //         try {
   //            // remove all of its children
   //            removeArtifacts(artifact.getChildren());
   //         } catch (OseeCoreException ex) {
   //            OseeLog.log(SkynetGuiPlugin.class, OseeLevel.SEVERE_POPUP, ex);
   //         }
   //      }
   //   }

   public boolean hasAttributeMatches() {
      return true; //!attributes.isEmpty();
   }

   @Override
   public IEditorMatchAdapter getEditorMatchAdapter() {
      return this;
   }

   @Override
   public boolean isShownInEditor(Match match, IEditorPart editor) {
      IEditorInput ei = editor.getEditorInput();
      if (ei instanceof ArtifactEditorInput) {
         ArtifactEditorInput fi = (ArtifactEditorInput) ei;
         return match.getElement().equals(fi.getArtifact());
      }
      return false;
   }

   @Override
   public Match[] computeContainedMatches(AbstractTextSearchResult result, IEditorPart editor) {
      IEditorInput ei = editor.getEditorInput();
      if (ei instanceof ArtifactEditorInput) {
         ArtifactEditorInput fi = (ArtifactEditorInput) ei;
         return getMatches(fi.getArtifact());
      }
      return EMPTY_ARR;
   }

   @Override
   public IFileMatchAdapter getFileMatchAdapter() {
      return null;
   }
}

Back to the top