Skip to main content
summaryrefslogtreecommitdiffstats
blob: fe10af4287176400695e2528b53ed07fa7245aed (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
/*******************************************************************************
 * Copyright (c) 2011 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.display.view.web.components;

import java.util.ArrayList;
import java.util.Collection;
import org.eclipse.osee.display.api.components.SearchResultComponent;
import org.eclipse.osee.display.api.data.SearchResultMatch;
import org.eclipse.osee.display.api.data.WebArtifact;
import org.eclipse.osee.display.view.web.CssConstants;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;

/**
 * @author Shawn F. Cook
 */
@SuppressWarnings("serial")
public class OseeSearchResultComponent extends VerticalLayout implements SearchResultComponent {

   private WebArtifact artifact;
   private final Collection<SearchResultMatch> matches = new ArrayList<SearchResultMatch>();
   private boolean showVerboseSearchResults = true;
   private final int TOPBOTTOM_VERT_SPACE = 8;

   public OseeSearchResultComponent() {
      //Stupid hack. Web layout is driving me crazy.
      //setHeight(65, UNITS_PIXELS);
      this.setSizeUndefined();
   }

   private void createLayout() {
      //    Layout:
      //     (0)   ArtName [ArtType]
      //     (1)   breadcrumb #1 >> breadcrumb #2 >> 
      //     (2)    match hint #1
      //     (n-1)  match hint #n
      //      ...
      //     (n)   [spacer]

      HorizontalLayout row0 = new HorizontalLayout();

      if (artifact != null) {
         OseeArtifactNameLinkComponent artifactName =
            new OseeArtifactNameLinkComponent(artifact, CssConstants.OSEE_SEARCHRESULT_ARTNAME);
         Label spacer1 = new Label("");
         spacer1.setHeight(null);
         spacer1.setWidth(15, UNITS_PIXELS);
         Label artifactType = new Label(String.format("[%s]", artifact.getArtifactType()), Label.CONTENT_XHTML);
         artifactType.setStyleName(CssConstants.OSEE_SEARCHRESULT_ARTTYPE);
         row0.addComponent(artifactName);
         row0.addComponent(spacer1);
         row0.addComponent(artifactType);
         row0.setComponentAlignment(artifactName, Alignment.BOTTOM_LEFT);
         row0.setComponentAlignment(artifactType, Alignment.MIDDLE_LEFT);

         Label bottomSpacer = new Label("");
         bottomSpacer.setHeight(TOPBOTTOM_VERT_SPACE, UNITS_PIXELS);

         Label topSpacer = new Label("");
         topSpacer.setHeight(TOPBOTTOM_VERT_SPACE, UNITS_PIXELS);

         addComponent(topSpacer);
         addComponent(row0);
         if (showVerboseSearchResults) {
            OseeBreadcrumbComponent breadcrumbComp = new OseeBreadcrumbComponent(artifact);

            addComponent(breadcrumbComp);

            for (SearchResultMatch match : matches) {
               OseeSearchResultMatchComponent matchComp = new OseeSearchResultMatchComponent(match);
               addComponent(matchComp);
            }
         }
         addComponent(bottomSpacer);
      }
   }

   @Override
   public void setArtifact(WebArtifact artifact) {
      this.artifact = artifact;
      removeAllComponents();
      createLayout();
   }

   @Override
   public void addSearchResultMatch(SearchResultMatch match) {
      matches.add(match);
      removeAllComponents();
      createLayout();
   }

   private class OseeSearchResultMatchComponent extends HorizontalLayout {
      public OseeSearchResultMatchComponent(SearchResultMatch match) {
         Label matchLabel = new Label(String.format("%s: ", match.getAttributeType(), Label.CONTENT_XHTML));
         matchLabel.setStyleName(CssConstants.OSEE_SEARCHRESULT_MATCH);
         Label spacer4 = new Label();
         spacer4.setWidth(15, UNITS_PIXELS);
         Label matchLabelHint = new Label(String.format("%s", match.getMatchHint()), Label.CONTENT_XHTML);
         Label spacer3 = new Label();
         spacer3.setWidth(15, UNITS_PIXELS);
         Label matchManyLabel = new Label(String.format("(%d matches)", match.getManyMatches()), Label.CONTENT_XHTML);
         matchManyLabel.setStyleName(CssConstants.OSEE_SEARCHRESULT_MATCH_MANY);

         addComponent(matchLabel);
         addComponent(spacer4);
         addComponent(matchLabelHint);
         addComponent(spacer3);
         addComponent(matchManyLabel);
      }
   }

   @Override
   public void setErrorMessage(String message) {
   }

   public void setShowVerboseSearchResults(boolean showVerboseSearchResults) {
      this.showVerboseSearchResults = showVerboseSearchResults;
      removeAllComponents();
      createLayout();
   }
}

Back to the top